Whenever we import the database we need to install the passport as it is not able to access the previous client secret. We need to change the new client secret after it is installed in the projects to all the locations required.
php artisan passport:install
For generating key we use the following command
php artisan key:generate
Then we need to run few commands for convenience so that we don’t get errors.
If the error shows asReplicating claims as headers are deprecated and will remove from v4.0. Please manually set the header if you need it replicated. then run the following command
composer require lcobucci/jwt=3.3.3
We can also check for updating composer and for this we use command
php artisan composer:update
to link the storage we need to run following command
php artisan storage:link
We can also do for our convenience migrating the database, for this we use command
In this tutorial we will learn about Array data type in PHP, before that you can see all the data types in PHP given below:
String
Integer
Float
Boolean
Array
Object
Null
In PHP we have a special data type where we can assign number of values in single variable using array.
For example: $a = array(10,20,30);
In PHP, there are three types of arrays:
Indexed array
Associative array
Multidimensional array
Indexed array:- PHP indexed array is an array which is represented by an index number by default. All elements of array are represented by an index number which starts from 0. PHP indexed array can store numbers, strings or any object. PHP indexed array is also known as numeric array.
Example:
Output:
We can also use <pre> tag to print both the key and value in the output.
Output:
Another way to write the array in PHP which shows the same output as above:
Crud is simply the basis of any web/app development features. All we have to do on any web page is Creating, Reading, Deleting, or Updating the content and that is known as the acronym CRUD. In this blog, we learn about how we perform CRUD operation in Laravel 5.8(PHP framework).
Step 0: Prerequisite
Install xampp a PHP development environment. (Version 7.4 best suited for 5.8 Laravel)
Install composer(to install libraries of Php for any application).
Install VS code(Code-editor).
Step 1 : Download/install Laravel 5.8
Go to command prompt and then go to the xampp folder in C drive by cmd. [C:\xampp\htdocs\]
It will install laravel 5.8 in your xampp/htdocs folder, and the folder name in which the Laravel is installed is “crud”(You can change this name of the folder while writing the command in cmd).
Step 2 : Create the Database
For the connection of the database first we have to run “xampp control pannel”.
Then in action tag start the Apache and MySQL.
and then click on Admin of MySQl. It will redirect tohttp://localhost/phpmyadmin.
Go to the database.
Give the name of the database and click create.
Step 3: Connection to the database.
In the .env file of the Laravel folder(named crud in this blog) open it with VS Code. Change your code to this.
You can use any name of your table instead of create_crud_table. The above command is going to create a migration(PHP file by the name of the table) file in the database/migration folder.
Edit the code and paste this :
Now in the command prompt use the following command :
php artisan migrate
Step 5: Create a Model File in Laravel
php artisan make:model Crud -m
In cmd, use this command to create the model file(You can use any name instead of Crud while making other projects)
It will add a Crud.php file in the app folder and in this file in a variable define the table column.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Crud extends Model
{
//
protected $fillable = [
'first_name', 'last_name', 'image'
];
}
Step 6 : Creating the controller
Controller is used to handling the http request. They are stored in app/http/Controllers directory.
We have to create the controller using the command line:
php artisan make:model Crud -m
Note : For making CrudController file in controllers
php artisan make:controller CrudsController
Step 7 : Setting the Route
Setting the route of all the CrudController class method in route/web.php
Route::get('/', function () {
return view('welcome');
});
Route::resource('crud', 'CrudController');