Moenchfracht

Moenchfracht

Member Since 1 Year Ago

Experience Points 2,570
Experience
Level
Lessons Completed 13
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

20 Jan
2 days 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 :)

18 Jan
4 days 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
1 week 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 :/

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
1 week 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
2 weeks 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
2 weeks 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
1 month ago

Moenchfracht left a reply on Filesystem Disk Per User

@MITHRANDIR - Thanks! It works :)

17 Dec
1 month 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)?

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

@CRNKOVIC - A new service provider or is it also possible to put it in the boot method in AppServiceProvider?

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
4 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
5 months ago

Moenchfracht left a reply on Auth With Two Tables

@Snapey It works "better"... If I chose the wrong company I get the "These credentials do not match our records." error in the login view. When I chose the right one, the login view is shown again without error. :(

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!

@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
5 months 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. 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. :)

31 Jul
5 months 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:


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!

15 Jun
7 months 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 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
7 months 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.

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
10 months 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?

Moenchfracht started a new conversation Relationship (again...)

Sorry for this really simple question. But I don't get it from the manual. :( I have 2 models/tables. One for pictures and one for artists. In my picture migration I made a reference to my artists table: $table->foreign('artist_id')->references('id')->on('artists')->onDelete('set null'); and in the model:

    public function artist() {
       return $this->hasOne('\App\Artist');
    }

The artists model has:

    public function picture() {
        return $this->hasMany('\App\Picture');
    }

How can I get the firstnameand lastnamefrom the artist when I get a picture by it's id? Thanks for help!

26 Feb
10 months ago

Moenchfracht left a reply on Relationships Not Working (LogicException?)

Thanks a lot @ruman Sometimes there are only small things that are missing. :D

Moenchfracht left a reply on Relationships Not Working (LogicException?)

It's from here: $collection = App\Collection::find(1);

And it returns:

=> App\Collection {#769
     id: 1,
     name: "TestCollection",
     location: "Herg",
     user_id: 1,
     created_at: "2018-02-24 20:01:36",
     updated_at: "2018-02-24 20:01:36",
   }

Moenchfracht started a new conversation Relationships Not Working

Hello. I try to build a relationship between my tables users (original from laravel) and collectionson Laravel 5.6.

Schema collections:

        Schema::create('collections', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('location');
            $table->integer('user_id')->unsigned()->nullable();
            $table->foreign('user_id')->references('id')->on('users')->onDelete('set null');
            $table->timestamps();
        });

The User model:

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

The Collection model:

    public function collection() {
        $this->hasMany('\App\Collection');
    }

I try to get the user->name using artisan tinker:

>>>  $collection->user()->get();
PHP Error:  Call to a member function get() on null on line 1
>>>  $collection->user()->name;
PHP Notice:  Trying to get property of non-object on line 1

Where is my mistake? Thanks!

06 Feb
11 months ago

Moenchfracht left a reply on Collections Macros

@skliche Thank you very much. Works perfect (also the hint with the date mutators :) )!

05 Feb
11 months ago

Moenchfracht started a new conversation Collections Macros

Hello! I am getting a collection from a DB query. This query returns starttime and endtime. I try to add a "difference" to this collection. I think the best way to do this is using a macro, but I'm new to this and can't find the right way to do that. At the moment I'm iterating through the items and try to put the values into the collection but that's not working.

        foreach ($zeiten as $tag) {
            $arbeitStart = DateTime::createFromFormat('H:i:s', $tag->kommt);
            $arbeitEnde = DateTime::createFromFormat('H:i:s', $tag->geht);
            $arbeitEnde->modify('-30 minutes'); // Abzug 30 Minuten für Mittagspause
            $arbeitsZeit = $arbeitStart->diff($arbeitEnde);
            $zeiten->put('arbeitszeit', $arbeitsZeit);
        }

Thanks for help :)