Moenchfracht

Moenchfracht

Member Since 1 Year Ago

Experience Points 2,730
Experience Level 1

2,270 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 13
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.

06 Aug
2 weeks ago

Moenchfracht left a reply on Two Auth Models

Thanks @snapey - I will think about it. :) But do you know how to implement the email verification with my system?

Moenchfracht left a reply on Two Auth Models

Sorry for bringing back (reuse) this thread. I solved this with 2 different guards. I want to use MustVerifyEmailso my classes for customers and companies look like this:

[...] use Illuminate\Contracts\Auth\MustVerifyEmail; [...] class Customer extends Authenticatable implements MustVerifyEmail [...] Schema for both models include the email_verified_atcolumn. The new user ist in the right table, and login works, but without the verification. Is there something I forgot?? Thanks (again)!

19 Jul
1 month ago

Moenchfracht left a reply on Two Auth Models

Thanks @jlrdw . So the best way is using different guards and have one user model with boolean is_company? And then have one model for the user details and one for company details?

Moenchfracht left a reply on Two Auth Models

Thanks, but I want to have complete different tables/models for users and companies.

Moenchfracht started a new conversation Two Auth Models

Hello, I need some help because I don't know where to start with this. In my project I need a registration (and login) for customers and one for companies. How do I start with the authentication? Should I use the standard auth mechanism or do I have to write everything manually?

Thanks!

11 Jun
2 months ago

Moenchfracht left a reply on Mix And Mdbootstrap

@ROBSTAR - Thanks! I will try this :)

07 Jun
2 months ago

Moenchfracht left a reply on Clicking Speed Test Results

You can store it in a database using ajax-calls after the user finished his clicking. But I would prefer to store it on the client side with cookies, because its really easy to achieve.

Moenchfracht started a new conversation Mix And Mdbootstrap

Hi. I try to add mdbootstrap to my laravel project using laravel mix. Can someone show me how to do it please? I also opened up a support case at https://mdbootstrap.com/support/jquery/install-pro-with-laravel-5-8/ (more detailed :-) ) Can anyone help me please?

20 Jan
7 months ago

Moenchfracht left a reply on XML From DB::table ToArray

I just solved it. I had to "manually" create this array. I thought it could be easier. But thanks anyway :)

Moenchfracht started a new conversation XML From DB::table ToArray

Hi. I try to convert an array from a database query to a xml file. I want to use https://github.com/spatie/array-to-xml for that Problem is, that my returned array has a numeric key and thats why array-to-xml throws an DOMException with message: Invalid character error Here is my array:

Array
(
    [0] => stdClass Object
        (
        [id] => 13551
        [outletname] => test1
        [createdbyname] => Test User1
        )
    [1] => stdClass Object
    (
        [id] => 13551
        [outletname] => test2
        [createdbyname] => Test User2
    )
)

Thanks for help :)

Edit: seems like more people have that kind of problems: https://github.com/spatie/array-to-xml/issues/16#issuecomment-434983316 I wrapped my array in a ['start'] array but now I get an exception htmlspecialchars() expects parameter 1 to be string, object given

18 Jan
7 months ago

Moenchfracht left a reply on Select Columns From Query

Ah ok. Then I will try the joins :) Thanks for your help, @vilfago !

Moenchfracht left a reply on Select Columns From Query

Why does collapsenot work here? https://laravel.com/docs/5.7/collections#method-collapse I only get empty results.

Moenchfracht left a reply on Select Columns From Query

@VILFAGO - Hehe. Thanks, I tried it and accidentally I tried it with the ids before i read your update.

Another question concerning this: Is it possible to "flatten" this collection into one dimension? I know there's a flattenmethod for collections, but that doesn't work as expected. :( I need the data to export it to a csv and I don't know how to handle this multidimension collection.

Moenchfracht started a new conversation Select Columns From Query

Hi, I have a query with relations: \App\Products::where('xfs', '>',10)->with('users')->get() I know the select method to get only specific columns. But this only returns columns from the Products model. How can I get specific columns from the User model? Thanks!

11 Jan
7 months ago

Moenchfracht left a reply on Notification And Broadcasts

@HFALUCAS - Yes, I changed it to fire it from the Controller... but the database entries are the same :/

Just found it :)

    public function __construct($dnid)
    {
        $this->dnid = $dnid;
    }

Had to change id to dnid (or whatever). Thanks for your help!!!

Moenchfracht left a reply on Notification And Broadcasts

@HFALUCAS -

class DeliverynoteSaved extends Notification implements ShouldQueue
{
    use Queueable;

    public $deliverynote;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($id)
    {
        $this->id = $id;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['database'];
    }

    /**
     * Get the database representation of the notification.
     *
     * @param  mixed $notifiable
     * @return array
     */
    public function toDatabase($notifiable)
    {
        return [
            'id' => $this->id
        ];
    }

I call it from the Event using

        \Notification::send($users, new \App\Notifications\DeliverynoteSaved($this->id));

I think thats the mistake....

Moenchfracht left a reply on Notification And Broadcasts

:) My notification table looks like this:

mysql> select * from notifications order by 'created_at' desc limit 2;
+--------------------------------------+-------------------------------------+-----------------+---------------+-----------------------------------------------+---------+---------------------+---------------------+
| id                                   | type                                | notifiable_type | notifiable_id | data                                          | read_at | created_at          | updated_at          |
+--------------------------------------+-------------------------------------+-----------------+---------------+-----------------------------------------------+---------+---------------------+---------------------+
| 0f1cadca-46d6-4fbd-a779-6fee5ca540f1 | App\Notifications\DeliverynoteSaved | App\User        |             3 | {"id":66}                                     | NULL    | 2019-01-11 09:01:51 | 2019-01-11 09:01:51 |
| 0f317d84-5069-44a4-91cd-88cbfcb677f6 | App\Notifications\DeliverynoteSaved | App\User        |             4 | {"id":"0f317d84-5069-44a4-91cd-88cbfcb677f6"} | NULL    | 2019-01-11 12:41:27 | 2019-01-11 12:41:27 |
+--------------------------------------+-------------------------------------+-----------------+---------------+-----------------------------------------------+---------+---------------------+---------------------+
2 rows in set (0,00 sec)

User '4' should also have data id:66, but it has the id from the table

Moenchfracht left a reply on Notification And Broadcasts

@HFALUCAS - Its working. Only strange thing is that when I send the notification to more than one user, the entries in the database have a wrong id stored. It's allways the id from the notification and not my data. :(

Moenchfracht left a reply on Notification And Broadcasts

@HFALUCAS - Thanks for that. One more question: where should I fire the notification from? And should I also fire the broadcasting-event? If so, which one first?

10 Jan
7 months ago

Moenchfracht left a reply on Notification And Broadcasts

OK. Now I'm broadcasting with my

            event(new \App\Events\NewDeliverynote($dn->id));

Should I change this to

$user->notify(new ...($dn->id));

or do I need both?

And how can I see which notifications a user has missed while he was logged out?

Moenchfracht started a new conversation Notification And Broadcasts

Hello, I need some help to understand the basics of notifications together with broadcasts. I am allready using broadcasts with pusher in my application. Now I want to save these broadcasts in the database. I want that the users see their missed broadcasts when they log in again. I am sure I need notifications for that. But I don't know where to start. I allready have my event which broadcasts a message with pusher. What's next? Thanks! :)

07 Jan
7 months ago

Moenchfracht left a reply on Relations

Thanks Snapey :)

Moenchfracht started a new conversation Relations

Hi! One (propably) easy question: I have a model with created_byand closed_by. Both fields are foreign keys from the user table. In my model class I have this method:

    public function user()
    {
        return $this->belongsTo('\App\User');
    }

How can I retrieve user mailadresses from creator and the one who closes the ticket? Thanks.

04 Jan
7 months ago

Moenchfracht left a reply on Value From Collection

@MANELGAVALDA - Thanks. I was trying with optionaltoo, but I had my brackets wrong, so it also threw this error.

Moenchfracht started a new conversation Value From Collection

Hi, a blade-view in a foreach-loop should show a number (amount). If I try it in a foreachloop it doesn't work (Trying to get property of non-object).

            @foreach ($allproducts as $product)
[...]
                    <td>{{ $entries->where('company_products_id', $product->id)->first()->amount}}</td>

When I try to dump only one value outside the loop it works:

{{ dump ($entries->where('company_products_id', 1)->first()->amount) }}

What is wrong here?

Thanks!

18 Dec
8 months ago

Moenchfracht left a reply on Filesystem Disk Per User

@MITHRANDIR - Thanks! It works :)

17 Dec
8 months ago

Moenchfracht left a reply on Filesystem Disk Per User

@KIMA - I added your code to my User class. How can I use it with the Storage facade (eg. Storage::put)? I tried it with

        \Auth::user()->getStorageInstance();
        return Storage::files();

But I only get the files from the directory storage_path('app/public/') (without the name directory). When I dump the $dirI get the right directory (with the name)... strange :/

Moenchfracht left a reply on Filesystem Disk Per User

@_STEFANZWEIFEL - Thanks! That was also my approach. I just need it rather for "companies" than users. The username was just for my testing playground. When a company changes its name I have more troubles than this :)

Moenchfracht left a reply on Filesystem Disk Per User

@KIMA - Thanks @kima Where is the best place to put this function?

Moenchfracht started a new conversation Filesystem Disk Per User

Hello, I'm thinking about a solution to store files for authenticated user in separate directories. I was trying to use the 'disks' in the filesystem.php like this. But it was not working. Is this a good idea to store files like this, and how can I do it in a "laravel-style"?

        'userdisk'=> [
            'driver' => 'local',
            'root' => storage_path('app/public/'.\App\Auth::user()->name.'/'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

Thanks!

27 Aug
11 months ago

Moenchfracht left a reply on Relationship With Array Of Ids

@NOMGUY Thanks. I tried this before. But when I try something like

 $prod = Product::find(1)

I get my Product with containers: "["1","2","3","5"]",

>>> $prod->containers;
=> [
     "1",
     "2",
     "3",
     "5",
   ]

Also works. But when I try

 $prod->containers()->get();

I only get the container with id "1"

Moenchfracht left a reply on Relationship With Array Of Ids

Product hasMany Container

Moenchfracht started a new conversation Relationship With Array Of Ids

Hi, my products (model below) can have one or more containers. How can I build the relationship between these two models?

class Product extends Model
{
[...]
    protected $casts = [
        "containers" => "array"
    ];

    public function container()
    {
        //return $this->hasMany('\App\Container', 'id','containers'); //??
        return \App\Container::whereIn('id', $this->containers);      //??
    }
}

Thanks!

02 Aug
1 year ago

Moenchfracht left a reply on Auth With Two Tables

Thanks @Snapey ! I tried before with:

        return $request->only($this->username(), 'password','company'); // <-- not company_id

because that is how my options value is named. Your answer really helped me!

I also had to update the line

        if($user->company()->where('id',$request->company_id)->first()) { // <-- was 'company' before

and now it works! THANKS!

@mpchean Why would you separate the databases? I think it doesn't make it easier. Make one user table with the company_id and one company table with unique company name. That should work too.

01 Aug
1 year ago

Moenchfracht left a reply on Auth With Two Tables

@mpchean The company_id is already in my users table. In my comment above you can see that my username and company_id makes a unique pair.

Moenchfracht left a reply on Auth With Two Tables

Thanks for your reply.

At the moment users are not unique because i want to leave every username for every company.

            $table->unique(['username', 'company_id']);

So company "Foo" can have user "Max" and company "Bar" can also have the user "Max".

I have no idea if that system can be done with Laravel - even I hope so. :)

Is it possible to use a custom Guard for this?

31 Jul
1 year ago

Moenchfracht started a new conversation Auth With Two Tables

Hi, I'm working on a app for more companies. User should log in with their username + password (both users-table) AND their company_id (stored in company-table). Users-table has this key:

$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');

User-model:

    public function company() {
        return $this->belongsTo('App\Company');
    }

I have updated the LoginController.php to overwrite the function from the AuthenticatesUsers-trait:

    public function credentials(\Illuminate\Http\Request $request)
    {
        return $request->only($this->username(), 'password', 'company');
    }

I think I am still missing some changes in the config\auth.php. Can please someone tell me where I have to link those tables? Thanks!

Update: Tried this in my LoginController, but it's not working at all :(

    protected function getLogin(\Illuminate\Http\Request $request)
    {
        $this->validate($request, [
            $this->username() => 'required|string',
            'password' => 'required|string',
            'company' => 'required|string',
        ]);

        if ($this->hasTooManyLoginAttempts($request)) {
            $this->fireLockoutEvent($request);

            return $this->sendLockoutResponse($request);
        }

        if ($this->attemptLogin($request)) {
            $user = \App\User::where('username', $request->username)->first();
            if (\App\Company::where('id', $user->company_id)->where('id', $request->company)->count() == 1) {
                return $this->sendLoginResponse($request);
            }
            return $this->showLoginForm($request);
        }

        // If the login attempt was unsuccessful we will increment the number of attempts
        // to login and redirect the user back to the login form. Of course, when this
        // user surpasses their maximum number of attempts they will get locked out.
        $this->incrementLoginAttempts($request);

        return $this->sendFailedLoginResponse($request);
    }
15 Jun
1 year ago

Moenchfracht left a reply on Storage And Retrieving Files

Thank you 36864 and Snapey. I changed my symlink to point to storage/app and now it's working :)

Moenchfracht left a reply on Storage And Retrieving Files

:)

OK. Thanks - I will try to find the mistake...

Moenchfracht left a reply on Storage And Retrieving Files

Yes, upload works. The file is stored in the folder storage/app/username

Moenchfracht left a reply on Storage And Retrieving Files

Yes, with php artisan storage:link

Moenchfracht left a reply on Storage And Retrieving Files

It's a broken image (error 404) with src= https://username.domain.com/storage/14264228_1080854508651067_2414239900366396390_n.png

And I am expecting to see the image. :)

Moenchfracht started a new conversation Storage And Retrieving Files

Hi, I am using subdomains for my users eg. username.domain.com. Users can upload images to their own storagedisks. in config\filesystems.php I have:

        'user' => [
            'driver' => 'local',
            'root'   => NULL, 
            'visibility' => 'public'
        ],

and my testfile (which should only display the image):

        config(['filesystems.disks.user.root' => storage_path().'/app/'.$username]);
        config(['filesystems.disks.user.url' => 'https://'.$username.'.domain.com/storage']);

The files are stored correctly under storage/username but I can not show the image in my views. I tried with

            <img src="{{ Storage::disk('user')->url('14264228_1080854508651067_2414239900366396390_n.png') }}">

But it doesn't work. Please help. Thanks :)

24 May
1 year ago

Moenchfracht left a reply on File Storage

Yes, I know :) But I want to access the array from my code. Badwords.php looks like this:

$badwords = ["blah", "one", "two"]; 

It seems as Laravel doesn't parse the file. It's treated like a string.

dd($badwords); results in Undefined variable: badwords

Moenchfracht started a new conversation File Storage

Hi, I know that I can load files from the 'local' disc using Storage::get(); I have a php-file: \storage\app\badwords.phpwhich only contains a big array with some words and want to parse it. Is this possible using the Storage facade? Normally I would use phps file() function. Thanks in advance.

27 Feb
1 year ago

Moenchfracht left a reply on Relationship (again...)

Many thanks to everyone who helped me with my issue!

If someone knows a good instruction for references and laravel: please post it here, so I don't have to bother you with my next problems :)

Moenchfracht left a reply on Relationship (again...)

One small step further :) I think I have some issues with my schema:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'artists.picture_id' in 'where clause' (SQL: select * from `artists` where `artists`.`picture_id` in (605, 606, 607, 609, 610, 613, 622, 623, 629))

Artists:

        Schema::create('artists', function (Blueprint $table) {
            $table->increments('id');
            $table->string('firstname')->nullable();
            $table->string('lastname');
            $table->date('birthdate')->nullable();
            $table->date('deathdate')->nullable();
            $table->string('birthplace')->nullable();
            $table->string('deathplace')->nullable();
            $table->string('nationality')->nullable();
            $table->text('biography')->nullable();
            $table->string('website')->nullable();
            $table->timestamps();

Pictures:

        Schema::create('pictures', function (Blueprint $table) {
            $table->increments('id');
            $table->string('title')->nullable();
            $table->integer('artist_id')->unsigned()->nullable();
            $table->integer('width')->nullable();
            $table->integer('height')->nullable();
            $table->string('material')->nullable();
            $table->string('technique')->nullable();
            $table->text('provenance')->nullable();
            $table->string('signature')->nullable();
            $table->string('subject')->nullable();
            $table->string('dating')->nullable();
            $table->string('type')->nullable();
            $table->string('attribute')->nullable();
            $table->integer('collection_id')->unsigned()->nullable();
            $table->foreign('artist_id')->references('id')->on('artists')->onDelete('set null');
            $table->foreign('collection_id')->references('id')->on('collections')->onDelete('set null');
            $table->timestamps();

Moenchfracht left a reply on Relationship (again...)

@zion Yes, I was looking for something like this, but...

Method Illuminate\Database\Eloquent\Collection::with does not exist.

Moenchfracht left a reply on Relationship (again...)

Thanks for your answers. I have more than one picture, so my code for retrieving the pics looks like $pics = Picture::where('collection_id', $coll->id)->paginate(9); In my view I iterate through this with a foreach loop.

Is it possible to "attach" the name of the artists to this data?