路由和控制器在Laravel 5.2中无法正常工作

时间:2016-08-22 11:40:38

标签: laravel-5.2

我在Laravel的一个教室项目中工作。当我插入数据时,我的另一条路线不起作用。但是当我改变路线以反转那段时间时,我的另一条路线起作用,而第一条路线不起作用。

这是我的路线:

Route::get('/class',[
'uses'=> 'classroom@getclass',
'as'=>'class',]);
另一个:

Route::post('/class', [
'uses' => 'classroom@showclass',
'as' => 'classdata,]);

我还给控制器:

public function getclass(Request $request)
{
    if (Input::has('post_comment'))
    {
        $status=Input::get('post_comment');
        $commentBox=Input::get('comment_text');
        $selectedStatus=Status::find($status);

        $selectedStatus->comments()->create([
        'comment_text'=>$commentBox,
        'user_id'=>Auth::user()->id,
        'status_id'=>$status
        ]);
        Flash::message('Your comments has been posted');
        return redirect(route('class'));
    }
    if(Input::has('status-text'))
    {
        $text=e(Input::get('status-text'));
        $rules = [
        'status_text'=>'required|string',
        ];
        $validator = Validator::make($request->all(), $rules);


        if(Input::hasFile('status_image_upload'))
        {
            $rules['status_image_upload'] = 'image';
            $validator = Validator::make($request->all(), $rules);
            if($validator->fails())
            {
                $image = $request->file('status_image_upload');
                $imageName = str_random(8).'_'.$image->getClientOriginalName();
                $image->move('status_images', $imageName);
                $userStatus = new Status();
                $userStatus -> status_text = $text;
                $userStatus -> image_url = $imageName;
                $userStatus -> type = 1;
                $userStatus -> users_id = Auth::user()->id;
                $userStatus -> save();
                Flash::success('Your status has been posted');
                return redirect(route('class'));
            }
        }
        else if ($validator->fails())
        {
            $userStatus = new Status();
            $userStatus -> status_text = $text;
            $userStatus -> video_url = $request['video_url'];
            $userStatus -> type = 2;
            $userStatus -> users_id = Auth::user()->id;
            $userStatus -> save();
            Flash::success('Your status has been posted');
            return redirect(route('class'));
        }
另一个:

 public function showclass(Request $request)
{
    $randomnumber = rand(50001,1000000);

    $classrooms = new Classrooms();
    $classrooms->class_name = $request['class_name'];
    $classrooms->subject_name = $request['subject_name'];
    $classrooms->section = $request['section'];
    $classrooms->class_code = $randomnumber;
    $classrooms -> user_id = Auth::user()->id;
    $classrooms -> save();
    return view('class', array('class' => Auth::user()) );
}

我的问题在哪里?我尝试了很多不同的方式。但没有解决问题。

0 个答案:

没有答案