RainDeer

RainDeer

Member Since 4 Months Ago

Experience Points
350
Total
Experience

4,650 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
0
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 1
350 XP
Sep
11
1 month ago
Activity icon

Started a new conversation Web Routing - ERR_TOO_MANY_REDIRECTS

I have a installation of Laravel 5.8.

What I'm trying to accomplish is that:

  • A user not logged in should land at auth/login
  • After a user logs in they should land on [email protected]'

A few simple web routing rules:

Route::get('/', function () {
    return view('auth/login');
});

Auth::routes();

Route::group( ['middleware' => 'auth' ], function()
{
    Route::get('/', '[email protected]');
    Route::resource('lists', 'ListController');
});

I have also changed all the redirects in all Http/Controllers/Auth classes to protected $redirectTo = '/lists';.

When I access the site I reach auth/login and login. I then get a ERR_TOO_MANY_REDIRECTS which appears to be between auth/login and [email protected]' but I can't figure out why that would happen?

Any ideas?

Aug
14
2 months ago
Activity icon

Started a new conversation Where Constraints On Children In Nested Eager Loading

I have 3 models:

  • User
  • Track
  • Genre

Relations:

User many-to-many with Track

Track many-to-many with Genre

I'm trying to eager load as below

$user = Auth::user();
$tracks = User::with(['tracks' => function($q){
            $q->where('release_date', 'like', '2011%')->wherePivot('rating', '>=', '3' );
        },'tracks.genres' => function($q){
            $q->where('genre', '=', 'Hip Hop');
        }])->get();

This gives me all tracks released 2011 with rating >= as expected but not only tracks with genre = Hip Hop but all tracks. However tracks with another genre are not populated with their genre in the result.

I could loop through the results to only get the ones with genre = Hip Hop but rather exclude them in the query.

How do I go about?

Jul
11
3 months ago
Activity icon

Started a new conversation Best Practice For Web Route When Attaching In Many-to-many Relationship

I have two models in a many-to-many relationship, User and Role.

What is the best practice of defining the route (web) for the attach function when a User gets a new Role? The Post method is already used by the Create function in the route.

Jul
01
3 months ago
Activity icon

Replied to Create Object Without Model

@JAYTEE - Works like a charm! Thanks @

Activity icon

Replied to Create Object Without Model

@JAYTEE - Thanks @jaytee! That removes the original error. Now I am able to create the object but I can't chain any parameters to it.

When using the exampel:

//chain some search paramater
$searchParameters->type('label')->format('lp')->year('1996');

I get the following error: Call to undefined method Jolita\DiscogsApi\SearchParameters::type()

Activity icon

Replied to Create Object Without Model

@NAKOV - The package I'm trying to use JolitaGrazyte/laravel-discogs refers to package JolitaGrazyte/discogs-api in which the SearchParametersClass is defined. But it seems like Laravel can't access it. I've imported the package into my providers list and am importing it in my controller by use Discogs;

Activity icon

Started a new conversation Create Object Without Model

I'm trying to use this package: https://github.com/JolitaGrazyte/laravel-discogs

Trying to do a search as per the documentation

$searchParameters = new SearchParameters();

//chain some search paramater
$searchParameters->type('label')->format('lp')->year('1996');

//do a search request with query = 'MoWax' and passing the SearchParameters object
$searchResult = Discogs::search('MoWax', $searchParameters);```

and get the following error
`Class 'App\Http\Controllers\SearchParameters' not found`

I am able to use all other features that don't require a `new SearchParameters()` object.

Any ideas?
Jun
04
4 months ago
Activity icon

Replied to Not Able To Get Socialite User

Gotcha! Yes I can get the access code in the callback method. Thank you!

Activity icon

Replied to Not Able To Get Socialite User

Tried it now, callback and registration still works but still can't get the user.

Activity icon

Started a new conversation Not Able To Get Socialite User

I have created a socialite registration process using the spotify provider. The authentication works fine, the user is created and logged in. But after registration I want to fetch the users Spotify auth token using: Socialite::driver('spotify')->stateless()->user() or Socialite::driver('spotify')->user().

The response I get is 400 Bad Request` response: {"error":"invalid_request","error_description":"code must be supplied"}

Here is my callback function

public function handleProviderCallback(\App\SocialAccountService $accountService, $provider)
    {

        try {
            $user = Socialite::with($provider)->user();
        } catch (\Exception $e) {
            return redirect('/login');
        }

        $authUser = $accountService->findOrCreate(
            $user,
            $provider
        );
        auth()->login($authUser);

        return redirect()->to('/home');
    }

SocialAccountService class

<?php

namespace App;

use Laravel\Socialite\Contracts\User as ProviderUser;

class SocialAccountService
{
    public function findOrCreate(ProviderUser $providerUser, $provider)
    {
        $account = LinkedSocialAccount::where('provider_name', $provider)
                   ->where('provider_id', $providerUser->getId())
                   ->first();

        if ($account) {
            return $account->user;
        } else {

            $account = new LinkedSocialAccount([
                'provider_id'   => $providerUser->getId(),
                'provider_name' => $provider
            ]);

            $user = User::where('email', $providerUser->getEmail())->first();

            if (! $user) {
                $user = User::create([  
                    'email' => $providerUser->getEmail(),
                    'name'  => $providerUser->getName(),
                ]);
            }

            $account->user()->associate($user);
            $account->save();

        return $user;

        }
    }
}

And HomeController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Socialite;
use Auth;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index()
    {
        //$user = Socialite::driver('spotify')->user();
        $user = Socialite::driver('spotify')->stateless()->user();
        var_dump($user);
        return view('home');
    }
}

What am I doing wrong?