Overview
Hello friends, I hope you’re doing well. Here I have brought some initial steps to take one step ahead in the laravel universe. Yes, here I am talking about laravel 6. So without wasting time let’s just get started with the installation process.
Prerequisite
PHP Version 7.2.0 or above
Installation
It’s not new in laravel, it is the same as it was in other versions, but it has a slight change on using default CSS and JS files.
To get a quick start with default laravel auth please follow the below steps.
Steps for default laravel auth
Step 1:
To get a fresh copy of laravel version 6, fire the following command in your terminal.
composer create-project –prefer-dist laravel/laravel project_name
> It’ll create a new project in your system.
NOTE: Remember this command will install laravel version 6 only if you have installed php version >= 7.2.0 in your system.
Step 2:
Before you move for the built-in login and registration process you have to install laravel UI as per the new Laravel version. For that fire the following command.
composer require laravel/ui
Step 3:
php artisan ui vue –auth
> Laravel 6 has removed “php artisan make:auth” command and instead, they design a new command “php artisan ui vue –auth” for a quick start on login and registration setup process.
REMEMBER: Here you’ll not find any “css” or “js” folder inside “public” folder of your project, it was created automatically in previous versions of laravel after firing “php artisan make:auth” command for the login and registration pages and other related pages design.
Now to get a scaffold of CSS and JS file you have to follow the below steps.
Step 4:
Fire the following command in terminal
npm install
> Which will install all the node dependencies in your project.
Step 5:
After installing npm, fire the next command
npm run dev
> As laravel built-in “webpack.min.js” file considers default scaffolding as SASS, you have to run this to make your own scaffolding.
NOTE: After running “npm run dev” command in terminal you’ll find 2 folders inside your public folder. Which will be “css” and “js” and you’ll find the files inside of it.
Now just refresh your login url and you’ll find the designed layout.
Laravel new error page from flare
Generally, we were facing error page something like this in the previous versions of laravel,
But for now, we won’t get this kind of error page. I mean we have a chance to get a more expressive error page. Which will express us nice design layout as well as it has some very good facility to show us our exact mistake.
For example,
When we define route in our route file as below,
Route::get(‘/test’, ‘TestController@test’);
And when we code in ‘TestController.php’ for “test()” and at this stage inside “test()” you’re returning a view which does not exist like,
public function test() { return view(‘test’); }
Now in general, It’ll go to fetch view file and show you the layout, but when it cannot find and fetch that particular file, it’ll show you an error page, but in laravel 6 error page will come something like this.
Wooahh !!!! It is really too much awesome thing don’t you think ?!
Anyway, did you notice? In this error page in green background you can see the suggestions as well.
But.. But.. But..
Generally, laravel provides this feature default in your laravel 6 installation. But if you don’t find “facade/ignition” package inside your composer.json file, it means you have to manually install in your project. For this you have to follow the below given steps.
Steps to solve error in browser
Step 1:
composer require facade/ignition
Step 2:
> Add the following code in your app/Exceptions/Handler.php file.
protected function whoopsHandler() { try { return app(\Whoops\Handler\HandlerInterface::class); } catch (\Illuminate\Contracts\Container\BindingResolutionException $e) { return parent::whoopsHandler(); } }
Step 3:
> To get configuration files for this installed package. You should fire the following command.
php artisan vendor:publish --provider="Facade\Ignition\IgnitionServiceProvider" --tag="config"
> Now see in “config” folder. You’ll find two new files
- flare.php
- ignition.php
In “ignition.php” file you can set your editor name and error page theme as I have set it to light right now. There might be so many functionalities to change for. By default, it’ll give you editor name as phpstorm and theme as light.
Anyway, Let’s go for the next step.
Step 5:
> In this step, you have to add or update some value of file config/logging.php.
In your ‘stack’ array, add one more value to the “channels” key and the value is ‘flare’. So your stack array would look like this now.
'stack' => [ 'driver' => 'stack', 'channels' => ['daily', 'flare'], 'ignore_exceptions' => false, ],
Okay so let’s go ahead and do one more change to the same file. Now what you have to do is to add flare array in main ‘channels’ array after ‘errorlog’.
'flare' => [ 'driver' => 'flare', ],
Okay done!!. Now no more changes require. You can refresh your error page and see the effect. If you cannot then clear the project cache or fire php artisan config:cache in your terminal.
Well adding this facade/ignition package will be helpful to any of the laravel version you’re working with.
Okay, so here we have learned about how to see error page in good designed and expressive layout. Now what we’ll learn is how to edit and resolve an error from browser’s error page.
Let me show one image so that you can get the basic idea about how we can edit and resolve our error from error page itself.
Okay so as you can see the picture of my error page now. Let me tell you first I have not imported App\User model, so that they are suggesting me to import package and get rid of error. But I have highlighted an edit pencil in my screenshot. So it’s an indication that you can edit it from the error page. And save it using command + S in MAC and in windows CTRL + S.
But before we resolve an error let me tell you that we have to install a package for it.
composer require facade/ignition-code-editor –dev
Okay so after installing above package your error page will be like online editor.
You can edit as I show you in the above screenshot. After changes, just save it via COMMAND + S / CTRL + S. You can also see the same changes in your main editor file.
So that was it.
BTW, there is one more new interesting feature and that is about Lazy collections. I will talk about it in my upcoming blog.
Cheers!! 🥂