@codemode so box is the representation of the URL. Something like http://domain.com/box. You are creating the location with this code. The second argument tells the route to run the controller method. Your controller will have a return view('all-boxes'); . So when the route runs the controller method, the method calls the view so it gets loaded when the URL is accessed. Hope that makes sense. It's MVC.
Route URL Vs View
Hi, I feel confused about the text we write in the routes file, and how we name the views. For example, what exactly is the "box" below?
Route::get('box', BoxController@index);
Is it just a url, and it does not matter if /box location actually exists or not? Also, if i want to display a list of boxes, i'll be creating a view, and probably name it "all-boxes". How does the "all-boxes" (view) url differ from "box" (route) ?
Sorry if the question is silly, i'm new. Thanks!
@codemode yes. Now that's only loading the view. If you need to pass objects you'll need to create them in the controller method. Here's one way to do it. Apologies in advance. I'm on my phone in between breaks during jury duty. So I can't use code styling. Here goes.
public function index() {
$data['boxes'] = Box::all();
return view('all-boxes', $data);
}
Now in your view, you can put the $boxes array through a foreach loop and display the record $box->column_name
There's other ways to do it using compact(), with(), but the example above is the "common" way.
Please or to participate in this conversation.