Laravel blade.php Files don't load in WAMP - laravel

I'm trying to load a .blade.php view with Laravel in WAMP. I have to view files for testing, test.php and test2.blade.php. When I load the non-blade view with
return View::make('test');
it works fine, but when I try to load the other view that uses blade like so
return View::make('test2');
I get an error
ErrorException
file_put_contents(D:\wamp\www\...\app\storage/views/407b5542021a967efb057132e71652cc):failed to open stream: No such file or directory
One thing I notice is that views in Laravel are in '\app\view', but when loading the .blade.php view it's trying to load it from '\app\storage/views'. What am I doing wrong here?

That error means that Laravel is trying to write data to your storage/view file, but it doesn't have permissions (write access). Storage/view is a folder for caching view files.It is default Laravel behaviour, so change permissions on whole storage folder, becuse there is more files inside, that Laravel will try to use for other purposes. For example, services.json is used when you add new service provider, and if it is locked, Laravel will complain.

Related

Livewire folder structure

I am quite new to Livewire and I feel a little bit confused about its folder structure.
I use the classic Laravel folder structure for my views and I put the components under the /resources/views folder; now with Livewire it seems that I am forced to put my components under /resources/views/livewire folder otherwise the component throws an error.
I also tried to change the view_path in my config/livewire.php file to resource_path('views'), instead of resource_path('views/livewire'), but it doesn't work.
The result is a messy structure like the following, where the users' components are in a different folder and I have to go back and forth to find what I want.
Wouldn't it be possibile to remove the /resources/views/livewire folder and put the components under the relative folder they belong to?
resources
views
users
index.blade.php
livewire
users
table.blade.php
the answer is the config file /config/livewire.php
'view_path' => resource_path('views/livewire'),
Just make sure you update all the Livewire class files views in their render function and that you clear any stale config information
php artisan cache:clear
edit: I have tested this and have regular Laravel blades along side livewire ones.

How is it possible to include a .blade file from outside of the Laravel project?

I have a Laravel 5.8 project and I'm using Blade to display the website.
However, I have .blade files outside of the Laravel project, that I'd like to #include() or display from the controller with return view(); with blade.
Here is a similar folder structure:
/var/www/examplesite1/
/var/www/examplesite2/
/var/www/laravel/
/var/www/storage/blade/
So for example the Laravel application is on the /var/www/laravel/ path. The blade file I'd like to get is from this path /var/www/storage/blade/.
What I tried was:
return view('/var/www/storage/blade/file.blade.php');
include('/var/www/storage/blade/file.blade.php');
None of them worked, becauase I got an error like this: View [.var.www.storage.blade.file.blade.php] not found.
I also tried it with omitting the 'blade.php' from the end, but it's the same.
Is it possible to include a blade file from outside the Laravel project? If yes, how?
You can add new directories to the views paths in config/views.php. https://laravel-news.com/laravel-view-path

Assets not loading in localhost for a laravel app

I have an application which has developed on laravel 5.7 and it's index.php is moved to root directory. Now when i tried to make the server up using php artisan serve command.
The website was loading but assets files like css and js not loading. Entire console showing errors and when i tried to see the asset file code through http://localhost:8000/assets/js/app.min.js
It was showing Error 404
The page you are looking for does't exist.
Can any one help me i am trying to resolve from past two days
Entire app is loading only view is not proper due to non loading of asset files

External PHP Include in Laravel

We run a main website which is not made in Laravel. A specific script on this website however is made in Laravel. We need this script (or to be exact, a specific view inside of it) to fetch some resources from the main website (PHP files which mainly include HTML). When, inside the Laravel application, we try to include these resources, we can not - as they don't exist in the Laravel project workspace. This results in an error that the file does not exist. Attempting to climb out of the project (../../../file.php) does not seem to help either.
We're including it this way:
<?php
include '~/template/nav.php';
?>
We don't wish to include this file into the actual Laravel project, as that would require having to update it twice to ensure they remain equal. Is there any way for us to include this "external" file in our view? Every bit of research done seems to suggest adding it into the project, which would just cause twice the amount of administration on updates.
Cheers!
Just faced same problem. My Laravel Project is an API that need's to include outside php file. So what I did was specify entire path:
include($_SERVER['DOCUMENT_ROOT'].'/../../my_example_file.php');
$_SERVER['DOCUMENT_ROOT'] will lead you to Laravel's public folder.

Laravel showing blank page

I just setup a Laravel 5 framework in my server by typing in terminal
laravel new blog (in "/var/www/html/" folder),
then changed the default config of Nginx so the root pointing to : root /var/www/html/blog/public;
of-course all the files are in place however I currently just see a blank page showing up ! I tried to put a html & PHP file in public folder and it all works fine. but not Laravel default index file. what am I missing here ?
For adding pages in Laravel you do not simply put files in /public. Please have a look at the official Laravel page if you want to create new views.
Laravel uses the MVC principle. So you need to have at least a view (the part which is displayed) and a controller which handles the view. To add a new Controller, please change to the project root cd /var/www/html/blog and type in php artisan controller:make AwesomeController which creates the controller in app/Http/Controllers/AwesomeController.php.
In this Controller you can simply return a view by adding return view('myview') to the index() Method for example. (The view has to exist at resources/views/myview.blade.php of course)
In the last step you need to tell Laravel how to call your controller. Please modify the routes.php file at app/Http/routes.php and add Route::get('foo', 'AwesomeController');. Now you need to tell composer that some of your controllers may have changed and composer needs to refresh the cache. Type in composer dump-autoload and start the development server php artisan serve.
By calling http://localhost:8000/foo (by default) you should see your View. Have a nice day!

Resources