Laravel short and sweet notes for all.

 1. Install laravel Developer.

   composer create-project laravel/laravel example-app

   cd example-app

   php artisan serve


2. vs code Extensions

   Php intelliSense

   Php Namespace Resolver

   Laravel Extra Intellisense

   laravel-blade

   laravel blade Snippets

   laravel goto view


3. Basic Routing

   php artisan sereve -start project

   web.php

   

   Ctrl+p for file search name.

  

   php artisan 

   php artisan route -h 

   php artisan route:list --except-vendor 


4. If not exist any route --

   Route::fallback(function(){

    return "<h1>Page is not found.</h1>";

   });


5. Use foreach loop 

   @php 

    $arr = ["salman khan","sahid kapoor","anil kapoor"];

   @endphp

   

   <ul>

   @foreach($arr as $value)

     <li>{{loop->iteration}}-{{ $value }}</li>

   @endforeach

   </ul>


6. @php

    $arr = ["test","test1","test2","test3"];

   @endphp


  <ul>

   foreach($arr as $value)

   if($loop->first)

   <li <style="color:red;">{{ $value }}</li>

   elseif($loop->last)

   <li <style="color:green;">{{ $value }}<li>

   else

   {{ $value}}

  <ul>


7.Blade Template: Template Inheritance

  

 (a.)layout.blade.php

    Home Page

    @yield('content')


 (b.)Home.blade.php

     @extends(layout)

    

     @section('content')

      <h1>Home page</h1>

     @endsection


    This Home page data show on layout.blade.php file.

  

8.  __invoke function call as constructor 


9. All data of route

   php artisan route:list  --except-vendor

 

10. for Create file 

    php artisan make:migration create_students_table

    php artisan migrate


11. Last file ko rollback karna

    php artisan migrate:rollback


12. ALL TABLE WILL REMOVE.

    php artisan migrate:reset


13. Rollback and migrate all tables 

    php artisan migrate:refresh


14. Make a project 

    1. composer create-project laravel/laravel Project_name

    2. composer require laravel/ui 

    3. Make database and connect to env

    4. Make auth 

       php artisan ui:auth

    5.php artisan migrate

    6.Download Template

      https://bootstrapmade.com/company-free-html-bootstrap-template/download/

    7.Make route for view and make index.blade.php 

    8.paste assets and forms  in public folder.

    9.copy index.html page data and paste index.blade.php

    10.run http://127.0.0.1:8000/


15. Make a project part 2.

    1.Start Project and run

    2.Make masterLayout.blade.php 

      1. paste head data

      2. @section('header')

         @show

              

         @yield('content')


         @section('footer')

         @show

    3. IN index.blade.php

        @extends('layouts.masterLayout')

        @section('content') 

        @endsection('content')

    4.Make UserController


16. Make Table 

    php artisan make:migration create_students_table

    php artisan migrate


17. Make foreign Id 

    $table->(id);

    $table->unsignedBigInteger('stu_id');

    $table->foreign('stu_id')->references('id')->on('students');

    

    **Here references from another table id 

      table from students.


18. Use casecade 

    when use casecade then simutenously change in both tables.

    -> use onUpdate('cascade') 

    ->use onDelete('cascade')


19. Seeding

     Insert intial data in Tables. after migration.

     

     Seeder:  Real Data

     Factory: Fake Data

   

     **Not use s with model and seeder name**

      Use in Migration s .

       

     ** Make Seeder **

     1.Make Model : php artisan make:model student

     2.Make Seeder: php artisan make:seeder StudentSeeder

     3.student::create([ ]);

     4.Seeders/DatabaseSeeder.php

        $this->call([

                  StudentSeeder::class

                   ]);

     5.php artisan db:seed


20. Laravel Model Factory 

    

    seeding

    1.Seeder ->Real Data

    2.Factory->Fake Data 

  php artisan make:model student

  php artisan make:factory StudentFactory



21. Topic of Laravel

    1. Razor pay payment gateway.

    2. social login 

    3. git 

    4. practice project .


22. Pluck 

    Return data in array format with value (unique).

    pluck only get two parameter and return as a  key and value .


23. Limit == take  (How Many value show. )  limit 3

    offset == skip  (from where to start .) offset 3


24. Use illuminate\Support\Facade\DB;

    Add New Record

    DB::table('users')->insert([

      'name' =>'Yahoo Baba',

      'email' =>' yahoo@gmail.com',    

    ]);   


    Update Existing Record

    DB::table('users')->where('id', 1)->update(['city' =>'agra' ]); 


    Delete Record 

    DB::table('users')->where('id',1)->delete();

    

25. For not use created_at and Updated_at 

     public $timestamps = false;



26. Upsert is use for add data and insert data k liye do parameter hote hai.

    parameter m unique vlaue k sath check karta hai (email).

    jo value unique h jaise email ager us mei change hai to new row insert ho jayghi.


27. Make Delete Button 

    <td><a href="{{route('delete.user',$user->id)}}" class="btn btn-danger btn-sm" >Delete</a></td>


28. User return on Home Page.

    if($user){

    return redirect()->route('home');

    }


29. Using Trancate 

    It is reset pirmary key and started with 1. 

    Delete started with previous value.


30. Single Value print 

    echo $request->name;


31. For show message on insert form.

    1. return Redirect()->back()->with('msg',"Data Inserted Successfully");

    2. @if(Session::has('msg'))

        <div class="alert alert-success">

           {!!  Session::get('msg') !!}

        </div>

       @endif



32. Laravel Validation 

    1. In Controller 

       $validate = $request->validate([

                   'name' => 'required',

                   'email' => 'required',

       ]);

   

    2.In Blade file

      <div style="color:red">{{ $errors->first('field Name') }}</div>

  

    3.! exclamatory sign 

       @error

        ('field Name') is-invalid

       @enderror


















  

Comments

Popular posts from this blog

My Sql Query ..

Interview question laravel.