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

LaravelPHP

Avatar of undefined
Last Comment
Chris Stanyon
SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo