Laravel showing blank page - laravel

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!

Related

How to properly duplicate a Laravel project in the same computer? [duplicate]

I have a Laravel 5.3 project which was created 5 months ago, today I made a duplicate from the project and I made some changes into the code.
When I edit the views in a blade.php file my project which I edited showed me the last project view, I made a new route in the new laravel project and in the routes works well, but still shows the last project view.
It's funny because the js files works pretty well, but the view doens't work. for example, I edit the profile.blade.php file and it shows the content from the last project, if I writte something new in the other view from the last project, it shows in the new project.
Any ideas?
Thanks in advance.
Your views/routes are compiled/cached.
The storage directory contains your compiled Blade templates, file
based sessions, file caches, and other files generated by the
framework.
The bootstrap directory contains files that bootstrap the framework
and configure autoloading. This directory also houses a cache
directory which contains framework generated files for performance
optimization such as the route and services cache files.
Run these commands
php artisan view:clear - Clear all compiled view
php artisan optimize --force - Optimize the framework for better performance
php artisan config:cache - Create a cache file for faster configuration loading
php artisan route:cache - Create a route cache file for faster route registration
Disable opcache from php.ini or use:
ini_set('opcache.enable', 0);

Laravel Class Controller not found because route is weirdly case sensitive

I wanted to add a controller to an already existing project of mine. Wrote a controller file, added the link in the admin_api route file and adjusted the view I needed.
On my local machine everything works fine.
On production it failed (it's supposed to retrieve a collection, which is then handled and displayed by a vue js component) and the network monitor showed an error 500.
I ssh into the website and ran php artisan route:list which gave me the error
In Container.php line 779:
Class App\Http\Controllers\Admin\Api\StatsController does not exist
Although the file StatsController is in App\Http\Controllers\Admin\API\
After playing around I realized that the problem was with the folder name "API", as laravel was looking for "Api". So apparently it's case sensitive.
Placing the controller in a new folder "Api" solved the issue.
Moving all the other "API" controllers to "Api" broke their routes.
when running php artisan route:list and in RouteServiceProvider all routes appear as under Admin/Api.
What I don't get is where is this being registered? Is there a way to change this?
I find it quite annoying that the controllers sit now in separate folders and it seems quite absurd to me. I don't quite get how the original controllers worked if they seem to contradict the other configurations.
Working with Laravel 5.7
I would appreciate any insights!
Thanks
Just put all the relevant api controllers in a folder named Api or API (just pick a convention and stick with it), then make sure that each file's namespace (declared at the top) is correct and reflects the folder structure you have chosen.
For example, if your controllers are in app/Http/Controllers/Admin/Api, check that each controller file begins with:
<?php
namespace App\Http\Controllers\Admin\Api;
// Rest of code...
StatsController.php must have the namespace as App\Http\Controllers\Admin\API. In Controller.php you have to import as App\Http\Controllers\Admin\API\StatsController. After that, run composer dump-autoload

Laravel using wrong controller

Laravel generates same controller in console directory and when i render dashboard component then laravel use controller from console directory which is wrong. So if I make changes in controller then its not reflecting.
After delete controller from console directory and then fire the composer dump-autoload its solved my issue

Set Laravel Application Urls

Fairly new to Laravel here and I'm struggling to understand how to make Laravel 5.2 aware of where it resides. Here's the issue:
I set up auth using php artisan make:auth, and can now see the lovely landing page, as well as login and register links in the menu. The problem is that these links don't go to the right place. They point to /login and /register in the code respectively, which translates into http://localhost/login or http://localhost/register. But since I'm not on a production site yet and am developing locally, my website resides at http://localhost/projectname/public.
I've gone into config/app.php and tried various values for the URL parameter, but these have no effect.
What can I do to get these links to reflect the full site URL, without manually entering it each time?
you can run the development server in laravel using this command
php artisan serve
Did you try that?
Use laravel url function:
{{ url().'/login' }}

Laravel blade.php Files don't load in WAMP

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.

Resources