ÔÚLaravelÖÐÔõÑù¾ÙÐÐÌøתºÍÊä³öÒ³Ãæ
laravelÊÇÒ»¿îÊ¢ÐеÄphp¿ò¼Ü£¬ËüÌṩÁËÇ¿Ê¢µÄ·Óɹ¦Ð§£¬Ê¹µÃÎÒÃÇÄܹ»ÇáËɵؽ«ÇëÇó·Óɵ½Ö¸¶¨µÄ¿ØÖÆÆ÷ÒªÁì¡£
ÔÚLaravelÖУ¬¿ØÖÆÆ÷ÒªÁìͨ³£ÈÏÕæ´¦ÀíÇëÇ󣬲¢·µ»ØÏìÓ¦µÄÏìÓ¦¡£È»¶ø£¬ÓÐʱ¼äÎÒÃÇÐèÒªÔÚ¿ØÖÆÆ÷ÒªÁìÄÚ²¿¾ÙÐÐÖض¨Ïò£¬»òÕßÊä³öһЩÊÓͼҳÃæ¡£ÄÇô£¬ÔÚLaravelÖÐÔõÑù¾ÙÐÐÌøתºÍÊä³öÒ³ÃæÄØ£¿±¾ÎĽ«Îª¸÷ÈËÏêϸÏÈÈÝLaravelÖеÄÕâÁ½ÖÖ²Ù×÷¡£
Ò»¡¢LaravelÖض¨Ïò
Öض¨ÏòÊÇÖ¸½«Óû§ÇëÇóÖØе¼Ïòµ½ÁíÒ»¸öURLµÄÀú³Ì¡£ÔÚLaravelÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃredirect()ÒªÁìÀ´ÊµÏÖÖض¨Ïò¡£
ÔÚ¿ØÖÆÆ÷ÒªÁìÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏ´úÂëÀ´Öض¨Ïòµ½Ö¸¶¨µÄURL£º
return redirect('http://www.example.com');
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëÖУ¬ÎÒÃÇʹÓÃredirect()ÒªÁìÀ´½¨ÉèÒ»¸öÖض¨ÏòÏìÓ¦¡£¸ÃÒªÁìÎüÊÕÒ»¸öURL²ÎÊý£¬ÌåÏÖÐèÒªÖض¨Ïòµ½µÄURL¡£ÔÚÏÖʵʹÓÃÖУ¬ÎÒÃÇÒ²¿ÉÒÔʹÓ÷ÓÉÃû³Æ»ò¿ØÖÆÆ÷ÒªÁìÃû×÷Ϊ²ÎÊý¡£
³ýÁËÖض¨Ïòµ½Ö¸¶¨µÄURLÖ®Í⣬ÎÒÃÇ»¹¿ÉÒÔʹÓÃÒÔÏ´úÂëÀ´Öض¨Ïòµ½Ö®Ç°µÄÒ³Ãæ»òË¢ÐÂÄ¿½ñÒ³Ã棺
return redirect()->back();
µÇ¼ºó¸´ÖÆ
»ò
return redirect()->refresh();
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬back()ÒªÁìÌåÏÖÖض¨Ïòµ½ÉÏÒ»¸öÒ³Ã棬refresh()ÒªÁìÌåÏÖË¢ÐÂÄ¿½ñÒ³Ãæ¡£
±ðµÄ£¬ÎÒÃÇ»¹¿ÉÒÔÔÚÖض¨Ïòʱת´ïһЩÊý¾Ý¡£ÀýÈ磬ÒÔÏ´úÂ뽫ÔÚÖض¨Ïòʱת´ïÒ»¸öÐÂÎűäÁ¿£º
return redirect('dashboard')->with('message', '²Ù×÷ÀÖ³É');
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëÖУ¬with()ÒªÁìÌåÏÖ½«Êý¾Ýת´ï¸øÏÂÒ»¸öÇëÇó¡£ÔÚÏÂÒ»¸öÇëÇóÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃsession()ÒªÁìÀ´»ñȡת´ïµÄÊý¾Ý£¬ÀýÈ磺
$message = session('message');
µÇ¼ºó¸´ÖÆ
¶þ¡¢LaravelÊä³öÒ³Ãæ
ÔÚLaravelÖУ¬ÎÒÃÇ¿ÉÒÔ½«¿ØÖÆÆ÷ÒªÁì·µ»ØÒ»¸öÊÓͼÀ´Êä³öÒ³Ãæ¡£ÊÓͼÎļþͨ³£ÉúÑÄÔÚresources/viewsĿ¼Ï¡£
Òª·µ»ØÒ»¸öÊÓͼ£¬ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏ´úÂ룺
return view('welcome');
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëÖУ¬view()ÒªÁìÌåÏÖ½¨ÉèÒ»¸öÊÓͼÏìÓ¦¡£¸ÃÒªÁìÎüÊÕÒ»¸öÊÓͼÃû³Æ×÷Ϊ²ÎÊý¡£ÔÚÏÖʵʹÓÃÖУ¬ÎÒÃÇÒ²¿ÉÒÔʹÓôøÓÐ’.’·ûºÅµÄ·¾¶À´Ö¸¶¨ÊÓͼÎļþËùÔÚµÄĿ¼¡£
ÊÓͼÏìÓ¦Öл¹¿ÉÒÔת´ïÊý¾Ý¡£ÀýÈ磬ÒÔÏ´úÂ뽫ÔÚÊÓͼÖÐת´ïÒ»¸öÃûΪ’title’µÄ±äÁ¿£º
return view('welcome', ['title' => '½Ó´ýÀ´µ½ÎÒµÄÍøÕ¾']);
µÇ¼ºó¸´ÖÆ
ÔÚÊÓͼÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃ{{ $title }}Óï·¨À´Êä³öת´ïµÄ±äÁ¿¡£
³ýÁË¿ÉÒÔÊä³ö¾²Ì¬Ò³Ã棬ÎÒÃÇ»¹¿ÉÒÔÔÚÊÓͼÖÐʹÓÃLaravelÌṩµÄBladeÄ£°åÒýÇæÀ´¶¯Ì¬ÌìÉúHTML´úÂë¡£ÀýÈ磬ÒÔÏ´úÂ뽫Êä³öÒ»¸ö´øÓбéÀúÊý¾ÝµÄ±í¸ñ£º
µÇ¼ºó¸´ÖÆ
ID | ÐÕÃû | ÄêËê |
---|---|---|
{{ $user->id }} | {{ $user->name }} | {{ $user->age }} |
ÉÏÊö´úÂëÖУ¬@foreachºÍ@endforeachÌåÏÖÒ»¸öÑ»·½á¹¹£¬{{ $user->id }}µÈÌåÏÖÊä³öÑ»·ÖеÄÿһ¸öÊý¾ÝÏî¡£
Èý¡¢LaravelÌøתÊä³öÒ³Ãæ
×ÛÉÏËùÊö£¬LaravelÖÐʵÏÖÌøתºÍÊä³öÒ³Ã涼ºÜÊÇÀû±ã¡£ÔÚÏÖʵʹÓÃÖУ¬ÎÒÃÇ¿ÉÒÔÍŽáÆðÀ´Ê¹Óã¬ÏȾÙÐÐÌøת£¬ÔÙÊä³öÏìÓ¦µÄÒ³Ãæ¡£ÀýÈ磬ÒÔÏ´úÂ뽫Ê×ÏȾÙÐÐÖض¨Ïò£¬È»ºóÊä³öÒ»¸ö´øÓÐÐÂÎűäÁ¿µÄÊÓͼҳÃ棺
return redirect('dashboard')->with('message', '½Ó´ý»ØÀ´£¬ÖÎÀíÔ±')->view('dashboard');
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëÖУ¬with()ÒªÁ콫ÐÂÎűäÁ¿×ª´ï¸øÏÂÒ»¸öÇëÇó£¬view()ÒªÁìÌåÏÖÊä³öÊÓͼҳÃæ¡£
ËÄ¡¢×ܽá
±¾ÎÄÏÈÈÝÁËÔÚLaravelÖÐʵÏÖÌøתºÍÊä³öÒ³ÃæµÄÒªÁì¡£ÔÚÏÖʵʹÓÃÖУ¬ÎÒÃÇ¿ÉÒÔÍŽáÆðÀ´Ê¹Óã¬ÎÞаÔËÓ㬵ִï×Ô¼ºµÄÐèÇó¡£Ï£Íû±¾ÎĶԶÁÕßÓÐËù×ÊÖú¡£
ÒÔÉϾÍÊÇÔÚLaravelÖÐÔõÑù¾ÙÐÐÌøתºÍÊä³öÒ³ÃæµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡