0
votes

I am trying to make a user profile with laravel! I can set the session I can see the data into the controller but now I want to compact the data for the profile blade.

public function profile(Request $request)
{
 $validatedData = $request->validate([
                  'email' => 'required|email',
                  'password' => 'required',
]);

 $user = DB::table('user_registers')
       ->where('email',$request->input('email'))
       ->first();

      if (!empty($user->email)) {
       if(Hash::check($request->password, $user->password))
       {
         $request->session()->put('data',$request->input('email'));
         if ($request->session()->has('data')) {
           return view('fontend.index')->with('data', $request->input('email'));
         }
       }else{
         return back()->with('password','Incorrect Password!');
       }
     }else {
       return back() ->with('email','Please Insert a valid email');
     }

    }
1
Why not read the docs? You may also use the global session PHP function to retrieve and store data in the session. When the session helper is called with a single, string argument, it will return the value of that session key. So just try session('data') in your view.Don't Panic

1 Answers

0
votes

if you want pass data to blade from controller you can do like this in your controller:

public function profile(Request $request)
{
    return view('fontend.index', ['user' => $user]);
}

check Basic Controllers doc

but if you want pass flash data and error masseage with old data to your blade in your blade file for feilds you can do like this:

<input id="name" type="text" class="form-control @error('name') is-invalid @enderror" name="name" value="{{ old('name') }}" required autocomplete="name" autofocus>

and for error message

@error('name')
      <strong>{{ $message }}</strong>
@enderror

check Old Input and validation doc

i hope can help you