0
我有兩條路線。第一個不工作,第二個工作。如果我把第二條路線放在第一條路線上,那麼它的工作和另一條路線不工作 這裏是我的路線:路線工作不正常
Route::any('/class',[
'uses'=> '[email protected]',
'as'=>'class',]);
Route::any('/class',[
'uses'=> '[email protected]',
'as'=>'class',]);
這裏是我的控制器:
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('classroom'));
}
}
return view('class',[
'posts'=>status::orderBy('id','DESC')->get()
]);}
另外一個
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()));
}
什麼應該現在做什麼?我認爲我的拖車網址是相同的,這是問題。如果我是正確的,我該如何解決這個問題?
我用它,但仍然是同樣的問題。 – Shuvo
你能告訴我你的新路線嗎? – James
我的新途徑是:Route :: get('/ class',[ '使用'=>'classroom @ getclass', 'as'=>'class',]); Route :: post('/ class',[ 'uses'=>'classroom @ showclass', 'as'=>'class',]);現在我的錯誤是Undefined variable:posts(查看:C:\ xampp \ htdocs \ myproject11 \ resources \ views \ class.blade.php),但是插入了數據。 – Shuvo