Alxxx's avatar
Level 1

Laravel 8 - Jetstream

New Laravel user here, having used other frameworks such as CakePHP. I'm trying to get my head around the docs and the myriad of available technologies such as Bootstrap, Blade, Vue, Fortify, Inertia, Tailwind, LIvewire and now Jetstream. I don't think it could be any more confusing to a new user!

I've set up a basic app using Jetstream, and like others had difficulty understanding where to go to edit the default logged in template. After some research found that I had to issue the following command

php artisan vendor:publish --tag=jetstream-views

This copied a number of files from

\vendor\laravel\jetstream\resources\views to \resources\views\vendor\jetstream which results in files being placed in app\resources\views\vendor\jetstream\components

Questions: Why was this process even necessary? Why, when Jetstream installed itself into the application, did it not place a copy of these components into a location where you'd expect to find them?

Question: Do I have to build all my components and then publish them in the same way?

Question: before I published the Jet components, the application still correctly rendered the page, does Laravel look in several locations for these files, and what takes precedent?

Secondly, I had a play with Laravel 7 and got my head around using @yield and @section, which seemed quite logical, and similar to what I'm used to, I but am having difficultly understanding components and the concept of {{ $header }} {{ $slot }} and things such as

The file Applayout.php in App\View\Components requests the app.blade.php file in resources\views\layouts so far so good.

In this file, it appears as though

a) navigation-dropdown.blade.php is requested via livewire?

b) {{ $header }} (somehow?) calls resources\views\dashboard.blade.php which contains ?

c) the file welcome.blade.php is requested via ?

Question: Why does this skeleton app appear to load things in three different ways? Question: As appears to load the main welcome page, why is {{ $page }} still needed in app.blade.php?

I have read all the docs, but am still struggling to understand the above. Any help appreciated.

0 likes
2 replies
jlrdw's avatar

You can use just like in laravel 7 the sections, just remember everything is optional you can choose what you want to use.

I have also done apps in cakephp. So just choose your CSS you want, your JS you want, Etc.

I use fetch js, regular js, bootstrap, and custom CSS.

For components and slots they are well covered in the documentation under the Blade chapter.

Snapey's avatar

Questions: Why was this process even necessary? Why, when Jetstream installed itself into the application, did it not place a copy of these components into a location where you'd expect to find them?

Good question. Taylor has come under some criticism for jetstream. As it is built as an optional package it tries to stay out of the way unless you want to customise it. This is though covered in the docs https://jetstream.laravel.com/1.x/introduction.html

Question: Do I have to build all my components and then publish them in the same way?

No, use of components is entirely optional. You can ignore the jetstream components or you can use them as templates for your own. I find reviewing the way Taylor builds the components very informative.

Question: before I published the Jet components, the application still correctly rendered the page, does Laravel look in several locations for these files, and what takes precedent?

Packages can register additional paths where views may be found. See https://laravel.com/docs/8.x/packages#views

Secondly, I had a play with Laravel 7 and got my head around using @yield and @section, which seemed quite logical, and similar to what I'm used to, I but am having difficultly understanding components and the concept of {{ $header }} {{ $slot }} and things such as

All these methods still exist. You could switch to docs to version 7 and not notice any problems if you built applications in this way. The component way is quite straight forward once you get your head around default slot and named slots. In fact these sames components existed in Laravel 7. There are videos here on Laracasts, also https://youtu.be/cQWeTnOwlm4

The file Applayout.php in App\View\Components requests the app.blade.php file in resources\views\layouts so far so good. In this file, it appears as though

a) navigation-dropdown.blade.php is requested via livewire? b) {{ $header }} (somehow?) calls resources\views\dashboard.blade.php which contains ? c) the file welcome.blade.php is requested via ?

I guess taylor was wanting to showcase some livewire code, but frankly the navigation is a poor use of livewire and does not benefit from being a livewire component at all.

$header is a named slot in the dashboard page, look for <x-slot name="header"> in the dashboard file. This section is inserted into {{ $header }} in the app.blade.php

The dashboard page also calls in a component <x-jet-welcome /> which delivers the /resources/views/vendor/jetstream/components/welcome.blade.php file. This is confusing because there is also a welcome.blade.php file in the resources/views folder. This one is the landing page of a default installation (without jetstream) and is returned as a view by the '/' route in web.php

Route::get('/', function () {
    return view('welcome');
});

Question: Why does this skeleton app appear to load things in three different ways? Question: As appears to load the main welcome page, why is {{ $page }} still needed in app.blade.php?

Sorry, I don't know what {{ $page }} is ?

Please or to participate in this conversation.