Link to home
Create AccountLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

How does one establish a quick and easy session variable in Laravel?

Here's the code in my Controller:

      public function practice($id) {
            $practice = practice_video::findOrFail($id);
            return view('practice', compact('practice'));            
      }

This syntax will give my user this screen:

User generated image
Perfect!

Thing is, I need to protect this page with a login dynamic. In other words, my user has to first login using their email and a predetermined password.

Having seen the "magic" of Laravel's "auth" dynamic, I didn't want to start from scratch using Vanilla PHP if there was quick and easy way to set up a login page that would establish a session variable that could be checked by the above page before it displayed the video.

How does one do that in the context of Laravel?

Here's the blade for the above page:

@extends('layouts.satellite')
@section('content')
<!-- Section: intro -->
<section id="intro" class="intro">
	<div class="satellite-content">
		<div class="container">
			<div class="row">
				<div class="col-xs-12 satellite_row">
					Hello, {{$practice->first_name }} {{ $practice->last_name }}!
					<br><br>
					Below you'll find the "practice video, "<b> 
					@if($practice->clip==1 || $practice->clip==2 || $practice->clip==3 || $practice->clip==4 || $practice->clip==5 || $practice->clip==6 || $practice->clip==7 || $practice->clip==8 || $practice->clip==9 || $practice->clip==10)
						DIAGNOSIS: DYSFUNCTIONAL SUCK PATTERN WITH FLACCID TONGUE | Video # {{ $practice->clip }}</b>
					@endif
					<br><br>
					You'll have access to this video until <b><?php echo date("m/d/Y", strtotime($practice->expiration_date));?></b>. If you have any questions, contact NOMAS International by clicking <a href="/contact">here</a>.
					<br><br>
					Thanks!
					<br><br>
					<div style="padding:10px; border:1px solid #ccc; text-align:center;">
						<div class="embed-responsive embed-responsive-16by9">
							<iframe class="embed-responsive-item" src="{{ asset('assets/videos/video_'.$practice->clip.'.mp4') }}" allowfullscreen autoplay=false></iframe>
						</div>
					</div><br><br>
				</div>
			</div>
		</div>
	</div>
</section>
@endsection

Open in new window

SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.