Saturday, February 4, 2023

Laravel 9 work

 Step 1: Create a first view page in laravel

Goto -> resources-> view

 Step 2: Added css and js.

Goto -> plublic-> makefolder



 Step 3: Make the navbar which is create to step by step

1. Now we have created the view page for links.



2. Create the new controller like.

Use the cammand:- php artisan make:controller Users

Users is a controller name.



3. Create pages and link to routes file.


4. Make the login form and get the post data.


5. DATABASE Configuration.

goto .evn file and configure your database


6. Create the new model like.

Use the cammand:- php artisan make:model Users

Users is a model name.

Step 1:- Check model is working or not.

        return User::all()




 Step :- Created the registration form



views/create.blade.php

@section('content')
<form action="/createsubmit" method ="POST" >
@csrf
  <div class="form-group">
    <label for="email">Name:</label>
    <input type="text" class="form-control" name="name" placeholder="Enter Your Name" id="name">
  </div>
  <div class="form-group">
    <label for="email">Email address:</label>
    <input type="text" class="form-control" name="email" placeholder="Enter email" id="email">
  </div>
  <div class="form-group">
    <label for="pwd">Password:</label>
    <input type="password" class="form-control" name="password" placeholder="Enter password" id="pwd">
  </div>
  <button type="submit" class="btn btn-primary">Submit</button>
</form>

@endsection



Controller/Users.php

function createsubmit(Request $req)
{
    $user = new User;
    $user->name = $req->name;
    $user->email = $req->email;
    $user->pass = $req->password;
    $user->save();

}

Models/User.php

class User extends Model
{
    use HasFactory;
    public $timestamps = false;
}

OUTPUT:-



Step: Fetch the user data.






Code:- 
routes/web.php

Route::get('list', [Users::class, 'list']);

Controller/Users.php

function list()
{
 $user = User::all();
 return view('userlist',['user' => $user]);
}

views/userlist.blade.php

<?php
// echo"<pre>";
// print_r($user);
// echo"<pre>";

?>
<div class="container mt-3">
<h1>User list project</h1>         
  <table class="table table-striped">
    <thead>
      <tr>
        <th>Firstname</th>
        <th>Lastname</th>
        <th>Email</th>
      </tr>
    </thead>
    <tbody>
        @foreach($user as $u)
      <tr>
        <td>{{ $u->name }}</td>
        <td>{{ $u->email }}</td>
        <td>{{ $u->pass }}</td>
      </tr>
      @endforeach
    </tbody>
  </table>
</div>

Step: Create the session and check the session.

Step:- Created the middleware(this is use for group of session which pages show on login user which show on logout user)
CMD:- php artisan make:middleware LogCheck

Step:- Now created the group middleware.

Step: Now check the middle ware is working or not.

Step: now put user list page inside the session condition.




No comments:

Post a Comment

If you have any problem please let me know.