In this tutorial about getting started with laravel, I saw this way of writing:
<code><?php namespace App\Http\Controllers; use App\Page; class HomeController extends Controller { public function index() { return view('home')->withPages(Page::all()); } }</code>
The withPages() function here does not exist in laravel at all. I searched on Google and could not find the answer. Based on my personal guess, I think the pages after withPages is a data variable mapped to the blade template. ($pages), but I didn’t find this way of writing when I checked the laravel documentation. I only found with('name', 'Victoria');
, this way of assigning variables. Does anyone know what is going on? Can you give me some information? Tell me what's going on? Quite urgent.
In this tutorial about getting started with laravel, I saw this way of writing:
<code><?php namespace App\Http\Controllers; use App\Page; class HomeController extends Controller { public function index() { return view('home')->withPages(Page::all()); } }</code>
The withPages() function here does not exist in laravel at all. I searched on Google and could not find the answer. Based on my personal guess, I think the pages after withPages is a data variable mapped to the blade template. ($pages), but I didn’t find this way of writing when I checked the laravel documentation. I only found with('name', 'Victoria');
, this way of assigning variables. Does anyone know what is going on? Can you give me some information? Tell me what's going on? Quite urgent.
The following are equivalent:
<code>view('home')->withPages(Page::all()); view('home')->with('pages', Page:all());</code>
In the previous chapter: Laravel 5 series introductory tutorial (2) [The most suitable Laravel tutorial for Chinese people] there is a comment:
withPages refers to querying the Pages table
This article is from last year and is relatively old. You can read the new version of the tutorial: 2016 version of Laravel series introductory tutorial (1)
Of course, Laravel Academy is also a good tutorial website.
You can understand this method as syntactic sugar