|
 |
|
สอบถามเรื่องการเช็คเงื่อนไข if else ภาษา laravel มือใหม่ |
|
 |
|
|
 |
 |
|
มันไม่ผ่าน นี่ไม่ผ่านแบบไหน มี error หรือไม่ ถ้ามีนำมาโพสต์ด้วย
หรือ ไม่ผ่านแบบไม่มีอะไรตอบกลับ
Framework ต่าง เป็น full dynamic render page เมื่อมีปัญหามักจะต้องดูทั้ง MVC ประกอบกัน
|
 |
 |
 |
 |
Date :
2020-06-25 04:30:51 |
By :
PhrayaDev |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ปัญหาอยู่ที่ return redirect('home');
มันหา home view ไม่เจอ...จะ redirect ไปหน้าไหน หน้านั้นต้องถูกสร้างขึ้นมาก่อนครับ
แต่ถ้ามั่นใจว่ามี home.blade.php แล้ว ลอง
Code (PHP)
return redirect()->route('home');
|
ประวัติการแก้ไข 2020-06-25 22:20:04
 |
 |
 |
 |
Date :
2020-06-25 22:10:57 |
By :
PhrayaDev |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันควรจะเป็นแบบนี้ไหม
Code (PHP)
if($request->age >= 200 && $request->age <= 300){
redirect('home');
}else{
return $next($request);
}
return redirect('home'); ถูกแล้วแฮะ ไม่เคยใช้ เลยงงกับไวยกรณ์
ถูกต้องก็ตามข้างบนเลย
return redirect()->route('home');
|
ประวัติการแก้ไข 2020-06-26 15:17:10 2020-06-26 15:18:21
 |
 |
 |
 |
Date :
2020-06-26 15:14:25 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เช็คในลักษณะ return $next($request); คุณต้องไปทำใน middleware ครับเช็ค
web.php
Route::group(['middleware' => ['web','rap']], function ()
{
Route::get('admin/dashboards',[
'as' => 'admin.dashboards.index',
'uses' => 'Backend\DashboardsController@index',
'age' => 20,
]);
});
middleware (rap)
public function handle($request, Closure $next)
{
$action=$request->route()->getAction();
asset($action['age'])? $age=$action['age'] : $age=0;
if($age >= 18 && $age <= 30)
{
return redirect()->route('home');
}else{
return $next($request);
}
}
หรือถ้าคุณต้องการ User Login คุณต้องสร้าง Authentication ก่อน ใน Middleware ค่อยทำการดึงด้วย $request->user()->age จากฐานข้อมูล Field age
|
ประวัติการแก้ไข 2020-06-28 12:42:03
 |
 |
 |
 |
Date :
2020-06-28 12:40:37 |
By :
Genesis™ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|