red security
red security

Reputation: 303

laravel send data to view via route and display it in view without altering url

on signup i am checking the invitation code the user uses using:

$match_code = DB::table('codes')->where('code', $code)->pluck('code');

        if($code == $match_code){

            $ip->save();

            $user->save();

            Auth::login($user);

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

        }else{

            return redirect()->route('home')->with('message','Invalid Invite Code');

        }

i tried adding this in my view :

@if(isset($message))
    <li>{{ $message }}</li>
@endif

but this does not display anything, i am new to laravel. i know this is basics but i have been googling for over 45 mins with no results

Upvotes: 0

Views: 75

Answers (1)

Mayank Pandeyz
Mayank Pandeyz

Reputation: 26258

The data you have send using with() is available in session, check this:

return redirect('dashboard')->with('status', 'Profile updated!');

After the user is redirected, you may display the flashed message from the session. For example, using Blade syntax:

@if (session('status'))
    <div class="alert alert-success">
        {{ session('status') }}
    </div>
@endif

Reference

Upvotes: 1

Related Questions