Laravel Tutorial Day 8

Learning Objectives: 1) Laravel Session Management. Store value to Session, Fetch value from the session. 2) Another Important Point we will discuss is File Upload. 3) Validation Controller

1.1 Store Value to Session

Route::get('/setsession', function () {

        session(['loginusername'=>'Adarsh Patel']);
        echo "done";
    
    });

1.2 Fetch Value from Session

  Route::get('/getsession', function () {

        echo session('loginusername');
        
        });

2.1 File Upload View Code

<form action="/fileupload" method="post" enctype="multipart/form-data">
@csrf
    <input type="file" name="image"> 

    <input type="submit" value="Submit">
</form>

2.2 File Upload Controller Code

public function fileupload(Request $request)
    {
        $request->file('image')->store('foldername');
    }

3.1 How to Add Validation in Controller Code

 public function save(Request $req)
    {

        $request->validate(
            [
                'pname'=>'required'
            ]
            );

        $pname = $req->pname;
        $pdesc = $req->pdesc;

        $p = new product;
        $p->name = $pname;
        $p->desc = $pdesc;
        $p->save();
    }

3.2 Add Validation Error Message in View

<form action="/product" method="post">
    @csrf
  
  <div class="container">
    <label for="pname"><b>Name</b></label>
    <input type="text" placeholder="Enter Product Name" name="pname" required>
    @error('name')
      {{$message}}
    @enderror
    <br/><br/>
    <label for="pdesc"><b>Desc</b></label>
    <input type="text" placeholder="Enter Desc" name="pdesc" required>
    <br/>    
    <button type="submit">Add</button>

</div>

The Role of Education in Our Life

The Role of Education in Our Life is Most Important. If we are educated properly with technical skills and fundamental skills, then we can make proper decisions when some situation occurs.

Let’s Understand by Example:

If Person is not educated and stuck in some problem, they will always try to fight with current situation and will be happy if he solves some minor problem, But what happens next, the same problem will come again into their life and he is repeating the same solution which he tried yesterday.

Now It’s time to think, If you are facing the same and same problem again then you need to change your way.

Now Let’s think that people is well educated then if he found the same problem many times then he will try to dig something in deep about their origin and will try to finish the problem permanently.

But here education is not only the degree you receive from School or College. Education should include the real life situations and it’s solution.