1. แสดงผลตัวแปรต่างๆที่ไปที่ view view('')->with('tasks', Task::all()); หรือ view('', ['tasks', Task::all()]); 2. route cache php artisan route:cache 3. ล้าง route cache php artisan route:clear 4. สร้าง csrf tokens field ให้กับฟอร์ม {{ csrf_field();}} 5. คำสั่งเกี่ยวกับการ Redirects return redirect()->to('login'); return redirect('login'); 6. route redirect เช่น return redirect()->route(''); return redirect()->route('', ['id', 99]); 7. redirect back() ใช้ redirect()->back(); หรือเขียนย่อๆ แค่นี้ back(); 8. redirect ไปที่ route ที่ชื่อว่า home home(); 9. refresh หน้า refresh(); 10. redirect โดยใช้ action() เช่น redirect()->action('ชื่อController@ชื่อmethod'); 11. สร้าง flash data session redirect()->with(['error'=>true, 'message'=>'Whoops! ']); 12. aborting the request abort(403, 'คุณไม่มีสิทธิ์ใช้งานส่วนนี้'); 13. return json return response()->json(User::all()); 14. ดาวน์โหลดไฟล์ return response()->download('', ''); หรือถ้าต้องการแสดงที่ browser ก็ใช้ return response()->file(''); 15.
บางท่านอยากมี Function ซักตัวหนึ่งไว้เรียกใช้ โดย Function สามารถใช้ได้ทุกทีทีเราอยากใช้ วันนี้ผมจะมานำเสนอ ไว้สำหรับเรียกใช้ Function กันครับ สร้างไฟล์ ให้เราสร้างไฟล์ php ในโฟลเดอร์ app หรือที่ไหนก็ได้ที่เราจะเรียกใช้มัน โดยที่ไฟล์ ของผมจะมี Function ตัวหนึ่งไว้สำหรับ Format วันที่ให้เป็นเวลาไทย ดังนี้ php function formatDateThat($strDate) { $strYear = date("Y", strtotime($strDate))+543; $strMonth= date("n", strtotime($strDate)); $strDay= date("j", strtotime($strDate)); $strHour= date("H", strtotime($strDate)); $strMinute= date("i", strtotime($strDate)); $strSeconds= date("s", strtotime($strDate)); $strMonthCut = Array("", "ม. ค. ", "ก. พ. ", "มี. ", "เม. ย. ", "พ. ", "มิ. ", "ส. ", "ต. ", "ธ.