tjcasner

Professional Athlete at MLS / USL

Experience

21,490

0 Best Reply Awards

  • Member Since 1 Year Ago
  • 213 Lessons Completed
  • 1 Favorite

5th April, 2018

tjcasner left a reply on Multiple Route Parameters Best Practice • 3 months ago

@Cronix I understand that part of route model binding.

What I'm saying is that I want the team wildcard in the route to be dependent on the organization wildcard in the route.

Both {organization}/{team} being passed through the route means I am trying to preserve the relationship that team belongs to organization while allowing the route to be loaded dynamically based on the organization/team selection.

4th April, 2018

tjcasner left a reply on Multiple Route Parameters Best Practice • 3 months ago

@Cronix I've tried to only pass the team through, but then Laravel throws an error for only trying to pass through one model when the route references two.

I could be doing it incorrectly, could you be a little more specific?

tjcasner left a reply on Multiple Route Parameters Best Practice • 3 months ago

@Snapey The problem I'm facing is:

Let's say I have Organizations A and B and Teams A and B.

Team A belongs to Organization A and Team B belongs to Organization B.

With the current code I have and passing $team and $organization through to the view, the Team to Organization model relationship is not being recognized, therefore the URL's

'/Organization_A/Team_A'

'/Organization_B/Team_A'

produce the same page with the same data.

3rd April, 2018

tjcasner started a new conversation Multiple Route Parameters Best Practice • 3 months ago

Looking for the the best way to use multiple parameters in routes.

I have seen Jeffrey use a custom path() function to help, but I am wondering if there is something more standard for controller use.

For example, I have two models Organization and Team. Team belongs to Organization. Route key names are both slug 'name'.

Route:

Route::get('/{organization}/{team}', '[email protected]');

Controller:

public function teamInfo(Organization $organization, Team $team)

{
    // best practice here
    return view( // team page here );
}

Thoughts?

21st March, 2018

tjcasner started a new conversation Dynamic Data In Vue Component • 4 months ago

Currently I am rendering data from a database into a list in a Vue component.

I am trying to make each list item a button that when clicked, renders the data bound from that list item in a container on the screen.

Current code:

<tbody>
    <tr v-for="exercise in exercises">
        <td><a @click="getExercise()" class="is-primary">{{ exercise.name }}</a></td>
        <td><span class="tag is-small is-tertiary">{{ exercise.duration }}</span></td>
        <td><span class="tag is-small is-danger">{{ exercise.load }}</span></td>
    </tr>
</tbody>

I want to render the data in the same page in this div

<div class="column is-two-thirds">
    <div class="box">
        [specific exercise data here]
    </div>
</div>

component js

export default {
    data() {
        return {
            exercises: [],
        }
    },
    created() {
        axios.get('/api/exercises')
            .then(({data}) => this.exercises = data);
    },
    methods: {
        getExercise() {
            axios.get('/api/exercises/' + this.exercise.id)
                
            }
        }
    }

api.php routes

Route::get('/exercises', function () {
    return App\Exercise::all();
});
Route::get('/exercises/{id}', function () {
    return App\Exercise::findOrFail($id);
});

My list data shows up fine from the axios call to the database, but I haven't been able to figure out what how to simply fill a div on the same page with information from the exercises that is clicked on. Any thoughts on the best way to do this?

13th June, 2017

tjcasner left a reply on Use The Same Login Form For Multiple Account Login • 1 year ago

Looks like you need some sort of roles/permissions tables within your database to differentiate between administrators and students.

Jeffrey has a couple of great lessons on this starting here:

https://laracasts.com/series/whats-new-in-laravel-5-1/episodes/13

Also check out the Gate component of the docs:

https://laravel.com/docs/5.4/authorization#gates

This is a robust way that your backend will sort out where your users are redirected.

12th June, 2017

tjcasner left a reply on How To Add In A New Library To Laravel Using Composer? • 1 year ago

Composer does all the work for you by creating a sproutvideo directory inside your vendor directory where the files are downloaded and stored.

tjcasner left a reply on How To Add In A New Library To Laravel Using Composer? • 1 year ago

Just add "sproutvideo/sproutvideo": "1.1.0" to your required dependencies in Laravel's composer.json file.

From there run composer update and it will automatically pull in the files to your vendor directory under vendor/sproutvideo.

10th June, 2017

tjcasner left a reply on A_guest_can_see_nothing_but_login • 1 year ago

The 'make:auth' command creates an auth middleware to separate guests from authenticated users. You can apply it to your routes as a group or individually.

https://laravel.com/docs/5.4/middleware#assigning-middleware-to-routes

Route::get('/home', function () {
    //
})->middleware('auth');

or:

public function __construct()
    {
        $this->middleware('auth');
    }

add this to all of your controllers which will automatically protect all of your views that require authentication

tjcasner left a reply on A_guest_can_see_nothing_but_login • 1 year ago

Assuming you haven't yet run 'make:auth', the simplest way to protect the rest of your routes would be (in my opinion) to use Laravel's built in Gate facade.

https://laravel.com/docs/5.4/authorization#gates

Using Gate, you can write a closure within the AuthServiceProvider file to check if the user is a guest in your system and protect all of your routes in one conditional.

Hope this helps!

9th June, 2017

tjcasner left a reply on Login And Home On Same Url ('/' ) • 1 year ago

If you look at the routes/web.php file within your application, you'll notice that Laravel provides an initial route:

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

    return view('welcome');

});

This tells Laravel to show the welcome view (resources/views/welcome.blade.php) when when routing to '/'. Simply return the view that contains your authentication logic when routing to the desired url '/'.

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

    return view('your-login-view-here');

});

Furthermore, you can use a controller or conditional logic within your route to return different views on the same url based on a user's authentication status. For example:

Route::get('/', function () {
    if (Auth::guest()) {
        return view('login'); // login page on '/'
    } else {
        return view('home'); // authenticated page on '/'
    }
});
Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.