I want to make a component in Laravel 8 by this command: php artisan make:component forms.input --view that means i want a component with only a Blade template and no class.
But i m Getting this ERROR: The "--view" option does not exist. Thanks for the tips
well, you may create a sub-directory under components let's say ...components/buttons.
Then just create a blade file representing your component for example round.blade.php.
use this component in any template like so <x-buttons.round /> and your component will be rendered correctly in your template.
Related
I'm using Laradock with Laravel 7.24, and I can't make a Blade template component work.
I've followed the tutorial from the official documentation page, so, inside the docker-machine executed:
php artisan make:component Alert
And placed the component inside of the layout blade template:
<x-alert/>
But it throws the following error:
Target class [Illuminate\Support\Facades\App\View\Components\Alert]
does not exist. (View: /var/www/resources/views/layouts/app.blade.php)
Does anyone know what is the issue?
Thanks!
Experienced with the same problem.
First of all, remove the file from app/view/components this path and run
php artisan view:clear this command.
Hope it will work.
To use the component anonymous you need to delete class app/View/Components/Alert.php, deleting the view folder worked for me.
I try to make my own version of a vendor blade template.
I dont want to extends the controller with the reference of the view.
So in my AppServiceProvider I add this line:
// Custom views for passport
$this->loadViewsFrom(__DIR__.'/../../resources/views/oauth/passport', 'passport');
I created a file named authorize.blade.php in /resources/views/oauth/passport
In the vendor controller method we can see this:
return $this->response->view('passport::authorize');
The problem is when I call the vendor controller method it loads his version of authorize.blade.php. I would like mine to be loaded and I expected the new line I added to AppServiceProvider to do that.
Passport comes with VUE components and views you need to publish first to override them. From the Laravel Passport page:
"If you would like to customize the authorization approval screen, you may publish Passport's views using the vendor:publish Artisan command."
All you need to do is run php artisan vendor:publish --tag=passport-views and the vendor views will be place in resources/views/vendor/passport, where you can edit them.
Use can use php artisan vendor:publish --tag=passport-views this will copy the views to your views folder for you to change.
So in my AppServiceProvider I add this line:
// Custom views for passport
$this->loadViewsFrom(DIR.'/../../resources/views/oauth/passport',
'passport');
You can use this option only by placing it in registry () instead of boot(). And then you can use your Views regardless of whether they were published in Vendor or not
I am just picking up using Laravel, but I dont like Vue and have been working with the React ecosystem and would like to use React instead of Vue. Laravel Mix doesnt give me the setup I want and so I figured I could use create-react-app.
Using Laravel Valet, I have started a project in which I have also installed create-react-app in a folder called ui, at the root of the Laravel installation.
My idea is to forego some of Laravel's functionality, namely the whole frontend.
I am attempting to require the react app build html file in resources/views/main.blade.php like so:
require_once __DIR__.'/ui/build/index.html';
This gives me the error:
Symfony \ Component \ Debug \ Exception \ FatalErrorException
(E_UNKNOWN) Illuminate\View\Engines\PhpEngine::main(): Failed opening
required
'/Users/Username/Sites/sitename/storage/framework/views/ui/build/index.html'
(include_path='.:')
This path is not correct, but I'm not sure why it is inserting /storage/framework/ into that path.
I have also tried the following, each with a similar error of Failed opening resource:
require_once('../../ui/build/index.html');
require_once($_SERVER['DOCUMENT_ROOT'].'/ui/build/index.html');
require_once(dirname(__FILE__).'/ui/build/index.html');
Laravel does not integrate with Vue, and Laravel Mix is a simple layer on top of Webpack. The default Laravel application ships with Vue scaffolding but removing that is as simple as deleting the files in resources/assets/js and if you wish to use another Javascript library then you can add that into your app.js instead.
The error you're receiving is because Laravel caches view files, meaning that they're served from the cache directory (which lives in storage/framework) so references like __DIR__ are referencing the cache directory, not the resources directory. You can see this in the documentation:
You should avoid using the DIR and FILE constants in your Blade views, since they will refer to the location of the cached, compiled view.
The correct approach to include files into your views with Blade is using the #include directive, e.g:
#include('ui.build.index')
Also, worth noting, that any time you do need to obtain the path to a file in your Laravel application you should use the base_path and app_path helpers.
Prior to continuing with development of your application you should read through the JavaScript & CSS Scaffolding documentation and the Blade documentation, as they contain a lot of information that will be very useful to you — for example, it explains how to replace Vue with React using a single command.
I'm building an app with Laravel 5.5. and I need to customize the pagination. I have to apply css class on the page link elements. Where I find the template to override?
You have to launch this command from terminal:
php artisan vendor:publish --tag=laravel-pagination
This creates the views in the resources/views/vendor/pagination directory.
Now you can apply your classes in the view: default.blade.php.
Read the documentation here: https://laravel.com/docs/5.6/pagination#customizing-the-pagination-view
You can specify your own pagination view:
{{ $paginator->links('view.name') }}
From the docs:
By default, the views rendered to display the pagination links are compatible with the Bootstrap CSS framework. However, if you are not using Bootstrap, you are free to define your own views to render these links. When calling the links method on a paginator instance, pass the view name as the first argument to the method
Or you can customize the default view.
From the docs:
However, the easiest way to customize the pagination views is by exporting them to your resources/views/vendor directory using the vendor:publish command:
php artisan vendor:publish --tag=laravel-pagination
This command will place the views in the resources/views/vendor/pagination directory. The default.blade.php file within this directory corresponds to the default pagination view. Edit this file to modify the pagination HTML.
Or, if you've just modified default Bootstrap classes, you can just load CSS after Bootstrap is loaded.
You need to publish the views first with php artisan vendor:publish --tag=laravel-pagination then they will appear in your resources/views/vendor/pagination folder and you can override them. Here is the reference
This command will place the views in the resources/views/vendor/pagination directory. The default.blade.php file within this directory corresponds to the default pagination view. Simply edit this file to modify the pagination HTML.
I'm using Symfony2.8 and when ever I use the command line for generating controllers and twig templates the templates are created under
MyBundle/Resources/views/home/home.html.twig
I want to follow the best practices suggested by symfony docs and have it inside of the
app/Resources/views/home/home.html.twig
I could just cut and paste the twig file and then change the {% extends %} if necessary, but then I would have lesser hair on my head because I would be pulling it out.
So what do I type in the prompt so that it generates the controller in the MyBundle as usual BUT the twig files would be under the global app/Resources/views folder
Thanks!
Edit: new extended question
After playing a little with the path for template generation i succeeded in placing the twig file inside the app/Resources/views/ folder.
Assuming that you have the standard architecture of a symfony2 app:
You could write the following path for the template when generator asks to specify the Templatename
Templatename (optional) [AppBundle:Post:get.html.twig]: ::../../../../app/Resources/views/Post/get.html.twig