Reputation: 325
In laravel ,how should I code the exception?
class DetailController extends Controller
{
public function index() {
$user_id = Request::get('id');
$user = User::find($user_id);
if($teacher) {
return view("detail",compact(["user"]));
}
return view("top");
// "Undefined variable: AAA (View:/Users/user2006734/lesson/lesson/resources/views/top.blade.php)"
}
}
When user_id is null,I want to make it redirect top page...
Using Route::redirect('/here', '/there', 301);
The Error does not occur but Redirected page is always blank.
Upvotes: 0
Views: 1306
Reputation:
Route::redirect('/here', '/there', 301);
is for redirectiong routes via web.php
.
In your controller use
return Redirect::route('home');
to redirect to the route named home
Upvotes: 1
Reputation: 13669
check Request has parameter , if not then redirect or render different view
public function index() {
if(Request::has('id')){
$user_id = Request::get('id');
$user = User::find($user_id);
return view("detail", compact(["user"]));
}else{
return view("top");
}
}
Upvotes: 1