PiotrG

PiotrG

Member Since 2 Years Ago

Experience Points 22,550
Experience Level 5

2,450 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 220
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.

04 Jul
2 weeks ago

PiotrG left a reply on API Resource Related Model Filtering

@mstrauss Thank you for trying to help, but I've given up on this for now since I can't get it to work as expected.

I've gone ahead and made filters on my Events Endpoint and dropped the User related Events like so:

    public function index()
    {
        $events = QueryBuilder::for(Termin::class)
        ->allowedFilters([
            Filter::exact('category', 'TERMINE_CLASS'),
            Filter::exact('user', 'TERMINE_USER'),
            Filter::scope('starts_before'),
            Filter::scope('starts_after'),
            Filter::scope('starts_between')
        ])
        ->paginate(100);
        
        return TerminResource::collection($events);
    }   

Now I just pass the user and category in my frontend Vue Component and get the data I need.

03 Jul
2 weeks ago

PiotrG left a reply on API Resource Related Model Filtering

The top one I already had, and that doesn't work as it returns all the events.

The bottom one does the same...

PiotrG left a reply on API Resource Related Model Filtering

select * from [BENUTZER] where exists (select * from [TERMINE] where [BENUTZER].[BENUTZER] = [TERMINE].[TERMINE_USER] and [TERMINE].[TERMINE_CLASS] = ?)

PiotrG left a reply on API Resource Related Model Filtering

select * from [BENUTZER] where exists (select * from [TERMINE] where [BENUTZER].[BENUTZER] = [TERMINE].[TERMINE_USER] and [TERMINE].[TERMINE_CLASS] = ?)

Looks good... I replaced the ? with 'Allgemein' in SQL Management Studio and it brought back only the records with TERMINE_CLASS 'Allgemein'

Very confused now :/

PiotrG left a reply on API Resource Related Model Filtering

Not sure where I could tack that on...

        $user = QueryBuilder::for(Benutzer::class)
            ->allowedIncludes('events')
            ->allowedFilters(Filter::exact('events.category', 'events.TERMINE_CLASS'))
            ->findOrFail($benutzer->BENUTZER_KEY)->toSql();

        return $user;

doing this only shows "select * from [BENUTZER]" in postman

PiotrG left a reply on API Resource Related Model Filtering

@MSTRAUSS - Unfortunately not, if I remove the column alias, I have to use events.TERMINE_CLASS. But even then, I still get ALL the events back, not only the ones I filter by.

PiotrG left a reply on API Resource Related Model Filtering

I've added Spatie Query Builder and edited my show function in my BenutzerController to:

        $user = QueryBuilder::for(Benutzer::class)
            ->allowedIncludes('events')
            ->allowedFilters(Filter::exact('events.category', 'events.TERMINE_CLASS'))
            ->findOrFail($benutzer->BENUTZER_KEY);

        return new BenutzerResource($user);

Hitting endpoint /api/benutzer/7?include=events&filter[events.category]=Meeting

still returns ALL the events...

PiotrG started a new conversation API Resource Related Model Filtering

Hello!

I am having trouble understanding how to filter a model resource relationship.

\Resources\User.php

<?php

namespace App\Http\Resources;

use App\Http\Resources\Termin as TerminResource;
use Illuminate\Http\Resources\Json\JsonResource;

class Benutzer extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->BENUTZER_KEY,
            'name' => $this->PERSON,
            'email' => $this->EMAIL,
            'username' => $this->BENUTZER,
            'password' => bcrypt($this->PASSWORT),
            'is_admin' => $this->SYSOP ? "true" : "false",
            'termine' => TerminResource::collection($this->termine)
        ];
    }
}

\Resources\Termin.php

<?php

namespace App\Http\Resources;

use Carbon\Carbon;
use Illuminate\Http\Resources\Json\JsonResource;

class Termin extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        // return parent::toArray($request);

        $start_date = Carbon::parse($this->TERMINE_VON_DAT)->format('Y-m-d');
        $start_time = Carbon::parse($this->TERMINE_VON_ZEI)->format('H:i');
        $start = Carbon::create($start_date . $start_time);

        $end_date = Carbon::parse($this->TERMINE_BIS_DAT)->format('Y-m-d');
        $end_time = Carbon::parse($this->TERMINE_BIS_ZEI)->format('H:i');
        $end = Carbon::create($end_date . $end_time);

        $allday = ($start == $end ? true : false);

        return [
            'id' => $this->TERMINE_KEY,
            'user' => $this->TERMINE_USER,
            'title' => $this->TERMINE_BETREFF ? $this->TERMINE_BETREFF : 'Kein Betreff',
            'location' => $this->TERMINE_ORT ? $this->TERMINE_ORT : 'Kein Ort',
            'start' => $start,
            'end' => $end,
            'allDay' => $allday,
            'category' => $this->TERMINE_CLASS ? $this->TERMINE_CLASS : 'Keine Kategorie',
        ];
    }
}

\Controllers\Api\BenutzerController.php

<?php

namespace App\Http\Controllers\Api;

use App\Benutzer;
use Illuminate\Http\Request;
use Spatie\QueryBuilder\Filter;
use App\Http\Controllers\Controller;
use App\Http\Resources\Benutzer as BenutzerResource;
use App\Http\Resources\BenutzerCollection as BenutzerCollectionResource;

class BenutzerController extends Controller
{
    public function index()
    {
        return new BenutzerCollectionResource(Benutzer::paginate(100));
    }

    public function show(Benutzer $benutzer)
    {
        return new BenutzerResource($benutzer->with('termine'));
    }
}

When accessing the

/api/benutzer/7

endpoint, I get the user and all their termine (appointments).

Problem is that this returns ALL the appointments without any filtering or pagination and of course the query takes a very long time.

How would I go about adding filtering on the "termine" relationship?

08 May
1 year ago

PiotrG left a reply on Login With Account Number, Username And Password

@jenky Yes the previous code was pasted by mistake. It was a first attempt before looking into the vendor folder properly. It however still didn't work until I put the use Request in.

PiotrG left a reply on Login With Account Number, Username And Password

After adding in

use Illuminate\Http\Request;

it all started working!

PiotrG started a new conversation Login With Account Number, Username And Password

Hi!

I would like to be able to change the default Auth to use an Account Number and a Username to log in.

I've changed the migration to include accountnumber and username and made a composite unique of those two.

I'm not interested in the register or reset password methods as I will be filling this table in from outside my Laravel App.

I've changed the Login View to include the accountnumber and username text fields.

I've added the following code in LoginController:

/**
 * Get the login username to be used by the controller
 * 
 * @return string
 */
public function username()
{
    return 'username';
}

/**
 * Get the login account number to be used by the controller
 * 
 * @return string
 */
public function accountnumber()
{
    return 'accountnumber';
}

/**
 * Handle an authentication attempt.
 *
 * @param  \Illuminate\Http\Request $request
 *
 * @return Response
 */
public function authenticate(Request $request)
{
    $credentials = $request->only('accountnumber', 'username', 'password');

    if (Auth::attempt($credentials)) {
        // Authentication passed...
        return redirect()->intended('/');
    }
}

/**
 * Get the needed authorization credentials from the request.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return array
 */
protected function getCredentials(Request $request)
{
    return $request->only('accountnumber', 'username', 'password');
}

I can log in using a username now but it doesn't take the accountnumber field into account. I can enter anything in that field and it still logs in me as long as username and password are correct.

Any ideas?

05 May
1 year ago

PiotrG left a reply on Inverse Polymorphic One-to-many

Okay, I will try.

I have a panel in the user view that displays group names that the user can create, like a folder structure. For example "My First Group", "Summer Trips", etc.

Also on this page is another panel that displays the items in the currently selected group. For example in Summer Trips are some Books, Pictures and some Videos.

The user can create a new book item and add it to their library. This book can then be put in a group the user chooses.

Additionally the user can also create subgroups and those again can have various items.

That's the use case.

PiotrG left a reply on Inverse Polymorphic One-to-many

Thanks for the answers, but they were not what I was looking for. I've since decided to go with the one-to-many relationship for each model. Maybe I will understand it later and then move things around.

PiotrG left a reply on Inverse Polymorphic One-to-many

But I am not storing Books and Videos in the same table, just references to the specific model in their respective tables.

04 May
1 year ago

PiotrG started a new conversation Inverse Polymorphic One-to-many

I've been trying to understand how to implement this or if I am just over-complicating things in my head.

I have a model called Group. I would like to be able to assign many different models to this group.

Of course I could set up a One-to-Many for each model to Group but I am thinking it would be more efficient to be able to assign any number of different models without having to configure each as One-To-Many and thereby having separate tables for each.

The examples in the Laravel Docs show the opposite. Many different models can have have "groupable" relationships, but I only want a Model to have 1 group.

Example:

Groups Table: Group ID Group Name Model Type Model ID 1 My Group App\Book 5 2 My Second Group App\Video 7 1 My Group App\Book 8

Am I going about this the wrong way? I feel I'm missing something...

13 Mar
1 year ago

PiotrG left a reply on Laravel And Laradock Development Application Workflow - From Local Development To Updating Live App!

@aurawindsurfing thanks for your write up, helped me as well!

Just a quick question:

When you say "You install another git in that folder and pull your private repository with your project...", I'm a little confused as to which folder you should commit/pull.

Coming from Homestead, I would commit from /laravel-app/, but here you are saying one should commit from /laravel-app/public. What about the changes in the other folders in /laravel-app/ ?

19 Feb
1 year ago

PiotrG left a reply on Logging Failing After Upgrade To Laravel 5.6 From 5.5

Running php artisan config:cache in the Laravel Homestead VM seems to have fixed the problem.

PiotrG left a reply on Video Request: Laravel Upgrade

Thanks Liam! Will check it out.

PiotrG started a new conversation Video Request: Laravel Upgrade

Would be great to get a very generic video on the steps you take when upgrading an existing project to a new version of Laravel.

PiotrG started a new conversation Logging Failing After Upgrade To Laravel 5.6 From 5.5

Getting this error when upgrading my project to 5.6 from 5.5.

There is no existing directory at "C:\code\laravel\ttc\storage\logs" and its not buildable: Protocol error

Removed the Log settings in config/app.php as per Laravel Upgrade Guide. Added config/logging.php as per Laravel Upgrade Guide. Using newest Laravel Homestead.