anantamu.com


Laravel Introduction



Laravel is MVC framework.



Installation:

Download composer https://getcomposer.org/download/
First, download the Laravel installer using Composer:
Run command prompt i.e composer create-project --prefer-dist laravel/laravel:^7.0 blog

1. .env.example change as .env

DB_DATABASE=uk
DB_USERNAME=root
DB_PASSWORD=

2.composer install

Run command prompt i.e composer install

3.php artisan migrate

Add the databse for run the command prompt i.e php artisan migrate

4.php artisan key:generate

Add the Key in .env file then run i.e php artisan key:generate

5.php artisan serve

Execute the program then run i.e php artisan serve

The basic concepts are:

1.Routing:

1.Get method:

 
Route::get('/show', 'RegistrationController@show'); or
Route::get('/show/{id}', 'RegistrationController@show');

2.Post method:

Route::post('/add', 'RegistrationController@add');

3.Middleware Method:

Route::group(['middleware' => 'auth'], function()
{
Route::get('/home', 'RegistrationController@home');
});

2.controllers in laravel

It is middle layer of view and model.

3.Views

View is presentation layer, Views contain the html code required by the application.
      

<html>
   <body>
        <h1> {{ $title }}</h1>
   </body>
</html>
      

4.Blade templating

Blade is a simple, yet powerful templating engine provided with Laravel. Unlike controller layouts, Blade is driven by template inheritance and sections. All Blade templates should use the .blade.php extension.

Defining A Blade Layout

Using A Blade Layout

5.Requests and Responses

Request:

To obtain an instance of the current HTTP request via dependency injection, you should type-hint the Illuminate\Http\Request class on your route closure or controller method. The incoming request instance will automatically be injected by the Laravel service container:

Response:

View Responses If you need control over the response's status and headers but also need to return a view as the response's content, you should use the view method:
return response()
->view('hello', $data, 200)
->header('Content-Type', $type);
Of course, if you do not need to pass a custom HTTP status code or custom headers, you may use the global view helper function.

6.Models and Migrations

Model: It allows interaction with the tables. Model gives to retrieve, insert, and update information into database table. For example: it has SQL queries in a Model.

Select all from table with Laravel and Eloquent

$resultSet = DB::table('registration')
->where('id', '1')
->get()
->toArray(); 

Insert form data into database using laravel

$valuesData = array('id' => '1','title' => '1','published_at' => Date('Y-m-d H:i:s'),'created_at' => Date('Y-m-d H:i:s'));
DB::table('registration')
->insert($valuesData);

Select data using where condition in Laravel

Registration::where('title','like', '%' . $request->input('name') . '%')
->where('status',1)
->get();

Select data using raw where condition in Laravel

Registration::whereRaw(" ( title = '".$name."') or ( title = '".$name."')")
->get();




List of All 223 Banks



Bank IFSC CODE

</