maltekiefer

Software Engineer at Germany

Member Since 9 Months Ago

Experience Points
4,530
Total
Experience

470 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
28
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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.

  • Community Pillar

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

Level 1
4,530 XP
May
02
6 days ago
Activity icon

Commented on Include CSS And JavaScript

Hello, which extension you use in phpstorm for the short writing of HTML? Which theme is it? How can I open the short dialog to select a file?

Apr
15
3 weeks ago
Activity icon

Replied to Access Multiple Relations On A Query

I created salestask_files like user_files

Activity icon

Replied to Access Multiple Relations On A Query

I come to a problem. I have a table salestasks that can have files too.

I added to the Salestask model this lines:

    public function files()
    {
        return $this->belongsToMany('\App\Models\File');
    }

To get the tasks I make this:

    public function getTasks()
    {

        $data = Salestask::with('files')->orderBy('date', 'desc')->get();

        return response()->json($data);
    }

But in the log I get this error:

[previous exception] [object] (PDOException(code: 42P01): SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation \"file_salestask\" does not exist
LINE 1: ...le_id\" as \"pivot_file_id\" from \"files\" inner join \"file_sale...
                                                             ^ at ..../vendor/laravel/framework/src/Illuminate/Database/Connection.php:343)

The same setting with users is working.

Apr
14
3 weeks ago
Activity icon

Replied to Can't Delete Files

That was it. Now it looks like this and it works:

    public function fileDelete($filename, $addressid){

        $path = File::where('name', $filename)->first();

        $filename_new = str_replace('/storage/assets/', '', $path->file_path);

        if (!Storage::disk('local')->exists('assets/'.$filename_new)){
            return response()->json('', 404);
        }
        File::find($path->id)->address()->detach($addressid);
        File::destroy($path->id);

        Storage::disk('local')->delete('assets/'.$filename_new);
    }
Activity icon

Started a new Conversation Can't Delete Files

Hello,

this is how I handle a file upload:

        $fileModel = new File;

        if ($request->file()) {
            $fileName = time() . '_' . uniqid() . '_' . $request->file->getClientOriginalName();
            $filePath = $request->file('file')->storeAs('assets', $fileName, 'local');

            $fileModel->name = $request->file->getClientOriginalName();
            $fileModel->file_path = '/storage/' . $filePath;
            $fileModel->save();

            $data = ['filename' => $fileName];

            $fileDB = File::where('name', $fileModel->name)->first();

            if ($request->addressid) {
                $address = Address::find($request->addressid);
                $address->files()->attach($fileDB->id);

            } elseif ($request->salestaskid) {
                $salestask = Salestask::find($request->salestaskid);
                $salestask->files()->attach($fileDB->id);
            }

            return response()->json($data, 200);
        }

That's works like a charm. Now I want to delete a file:

        $path = File::where('name', $filename)->first();

        $filename_new = str_replace('/storage/assets/', '', $path->file_path);

        if (!Storage::disk('local')->exists('assets/'.$filename_new)){
            return response()->json('', 404);
        }
        File::find($path->id)->address()->detach($path->id);
        File::destroy($path->id);

From the file the entry is deleted but not from the pivot table and not from the file system. What I am doing wrong?

Activity icon

Started a new Conversation A Mutator To Get File Extension

Hello,

I have a file model like this:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class File extends Model
{
    use HasFactory;
    protected $fillable = [
        'name',
        'file_path'
    ];

    protected $appends = ['extension'];

    public function getExtensionAttribute()
    {
        return \File::extension($this->filename);
    }

}

I tried to get the extensions. But the value is always empty, what I am doing wrong? This is how I store the file, maybe this is important:

$filePath = $request->file('file')->storeAs('assets', $fileName, 'local');
Activity icon

Replied to Access Multiple Relations On A Query

To easy, thanks

Activity icon

Started a new Conversation Access Multiple Relations On A Query

Good morning,

I have a question about querying data from the database, in conjunction with ->with().

Namely I have a table users, files and user_files. In the table files all files from the whole application are stored. user_files stores the userid and filesid.

If I now output the users, I want to pack the files to it right away.

I have now added this in the model of users:

    public function usersfile()
    {
        return $this->hasMany('\App\Models\UserFiles', 'userid', 'id');
    }

In the model UserFiles I have this:

    public function user()
    {
        return $this->hasMany('\AppApp Models\User', 'id', 'userid');
    }

How do I get it to work now, that I can use this in the user controller:

$data = User::with('userfile.files')->get();

The file model currently looks like this:

class File extends Model
{
    use HasFactory;
    protected $fillable = [
        'name',
        'file_path'
    ];

}
Mar
30
1 month ago
Activity icon

Replied to Switch From Join To Relations

Thanks for the hint. An entry in addresses can have several salestasks. These are connected by the addressesid field in the salestasks table.

Activity icon

Started a new Conversation Switch From Join To Relations

Good morning,

I currently have the job to convert an old PHP project into a Laravel project. Currently I have the following join which also works:

        $data = DB::table('salestasks')
            ->join('addresses', 'salestasks.addressid', '=', 'addresses.id')
            ->select('salestasks.*')
            ->where('delegatesid', $deletegateid)
            ->orderBy('id', 'desc')
            ->get();

Now I'm wondering if this could be more easily solved using relations.

My thought would be in the addressses a $this->hasMany(salestasks::class, 'addressid', 'id'); would that make sense?

That are currently the models:

class Address extends Model
{
    use HasFactory;

    protected $table = 'addresses';
    public const CREATED_AT = 'dbcreatedate';
    public const UPDATED_AT = null;

    protected $primaryKey = 'id';
}

class Salestask extends Model
{
    use HasFactory;

    protected $table = 'salestasks';
    public const CREATED_AT = 'dbcreatedate';
    public const UPDATED_AT = null;

    protected $primaryKey = 'id';
}
Mar
29
1 month ago
Activity icon

Started a new Conversation Best Way For Frontend In Vue.js And Backend In Laravel

Good day,

I would like to develop an application in Aue.js 3 with Primevue and use Laravel as backend for it.

Now I would like to know what is better in practice. I develop both in a Laravel environment. Or I develop backend and frontend separately from each other.

Surely both have advantages and disadvantages. How is it with you guys? How do you do it?

Jan
14
3 months ago
Activity icon

Started a new Conversation Can't Acces Database

Good day,

I am developing a Laravel application on an already based database, so no MIgrations are possible.

The table in the database looks like this:

CREATE TABLE addresssurveys
(
    id serial NOT NULL,
    addressid int4 NULL,
    addressqueueid int4 NULL,
    surveykey varchar(255) NULL,
    onefamilyhouse boolean default FALSE,
    twofamilyhouse boolean default FALSE
}

For this purpose I created the following model


<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Addresssurveys extends Model
{
    protected $keyType = 'bigInteger';
    protected $dates = ['created_at'];

}


Now if I try the following:

    public function index($key)
    {
        $survey = Addresssurveys::where('surveykey', '=', $key)->first();
        if ($survey === null) {
            return redirect('https://google.de');
        }
        return view('survey', ['key' => $key]);
    }

I get this error:

SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "addresssurveys" does not exist LINE 1: select * from "addresssurveys" where "surveykey" =  limit ... ^ (SQL: select * from "addresssurveys" where "surveykey" = CFIUZGBN54678978ZUKGBK limit 1)
Dec
17
4 months ago
Activity icon

Started a new Conversation Format Date Before Validation

This is how I validate some inputs:

        $request->validate([
            'holidaydate' => 'required|unique:holidays,holidaydate,NULL',
            'description' => 'required'
        ]);

Is there a way to format holidaydatebefore I validate it?

Dec
16
4 months ago
Activity icon

Replied to Combine Two Quries

Only one!

Activity icon

Started a new Conversation Combine Two Quries

Hello,

is there a way to combine these two queries to one? I want to reduce the request on the database:

$id = Projectvouchertype::where('internalname','=',\App\Models\Projectvouchertype::NAME_INVOICE)->first();
$book = Projectvoucher::where('projectvouchertype_id','=',$id->id)->get();
Dec
15
4 months ago
Activity icon

Replied to Query A Relationsship

It is a project that I have taken over and was not developed by me. I should only extend it accordingly and there is no time and money from the customer to change everything accordingly.

@turcinovic Unfortunately no, I have checked it accordingly.

In my model for Projectvoucher I have the following relationships:

	public function projectvouchertype() {
		return $this->belongsTo('\App\Models\Projectvouchertype');
	}
	public function projectvoucheritems() {
		return $this->hasMany('\App\Models\Projectvoucheritem', 'projectvoucher_id', 'id')->orderBy('linenum');
	}
Activity icon

Started a new Conversation Query A Relationsship

I am trying to query a releationship like this:

        $first = Projectvoucheritem::select('*','rentalstop AS tdate')
            ->with('transmissionbegin')
            ->with('transmissionend')
            ->with('transmissiondrivers.users')
            ->whereNotNull('rentalstop')
            ->whereDate('rentalstop', '>=', $start)
            ->whereDate('rentalstop', '<=', $end)
            ->with(['projectvoucher.projectvouchertype' => function ($query) {
                $query->where('internalname',  \App\Models\Projectvouchertype::NAME_RESERVATION)->orWhere('projectvoucher.projectvouchertype.internalname', \App\Models\Projectvouchertype::NAME_ORDER);
            }]);

But when I try it like this, I get this error:

SQLSTATE[42P01]: Undefined table: 7 ERROR: missing FROM-clause entry for table "projectvouchertype" LINE 1: ...hertypes"."id" in () and "internalname" =  or "projectvo... ^ (SQL: select * from "projectvouchertypes" where ("projectvouchertypes"."id" in (4) and "internalname" = reservation or "projectvoucher"."projectvouchertype"."internalname" = order) and "projectvouchertypes"."deleted_at" is null)

What I am missing here?

Dec
14
4 months ago
Activity icon

Replied to Set Correct Relationsship In The Model

So that should work, correct?

    public function transmissionbegin() {
        return $this->belongsTo('\App\Models\Transmissiontype', 'transmissionbegin_id', 'id');
    }
    public function transmissionend() {
        return $this->belongsTo('\App\Models\Transmissiontype', 'transmissionend_id', 'id');
    }
Activity icon

Replied to Set Correct Relationsship In The Model

OK I have a table (projectvoucheritems) hat included cars that I rent. I bring the cars to the customer , so I have a transmission to the customer a from the customer. I have a Transmission table that include the trucks for the transport.

So I need to add for every line in the projectvoucheritems tables a transmissionstart and transmissionend relationsship to the transmission table.

Activity icon

Replied to Set Correct Relationsship In The Model

So I must add in the model from Projectvoucheritem a

    public function transmissiontype() {
        return $this->belongsTo('\App\Models\Transmissiontype', 'transmissionbegin_id', 'id');
    }

But how can I add here two columns?

And in the model from Transmissiontype a

    public function projectvoucheritems()
    {
        return $this->hasMany('\App\Models\Projectvoucheritem')->orderBy('id', 'desc');
    }
Activity icon

Started a new Conversation Set Correct Relationsship In The Model

Hello,

I have created the following migration:

        Schema::table('projectvoucheritems', function (Blueprint $table) {
            $table->bigInteger('transmissionbegin_id')->nullable(true)->unsigned();
        });

        Schema::table('projectvoucheritems', function (Blueprint $table) {
            $table->bigInteger('transmissionend_id')->nullable(true)->unsigned();
        });

        Schema::table('projectvoucheritems', function (Blueprint $table) {
            $table->foreign('transmissionbegin_id')->references('id')->on('transmissiontypes');
        });

        Schema::table('projectvoucheritems', function (Blueprint $table) {
            $table->foreign('transmissionend_id')->references('id')->on('transmissiontypes');
        });

Now I tried to set up the correct relationship in the model files. But I don't know how to do it with two columns that have a foreign key on it. Can you guys help me?

Dec
10
4 months ago
Activity icon

Replied to Use Releationships With Select

yeah that's true there is a null, how can I ignore the entries ?

Activity icon

Started a new Conversation Use Releationships With Select

Hello,

when I make this:

$schedules = Projectvoucheritem::all();

I can use this:

@foreach ($schedules AS $vehicle)
    @if($vehicle->projectvoucher->projectvouchertype->internalname == \App\Models\Projectvouchertype::NAME_RESERVATION || $vehicle->projectvoucher->projectvouchertype->internalname == \App\Models\Projectvouchertype::NAME_ORDER)

But when I tried to use select to union two selects like this:

        $first = Projectvoucheritem::select('id', 'droplocation', 'vehicle_id', 'projectvoucher_id', 'rentalstop AS tdate');

        $schedules = Projectvoucheritem::select('id', 'droplocation', 'vehicle_id', 'projectvoucher_id', 'rentalstart AS tdate')
            ->union($first)
            ->orderBy('tdate')
            ->get();

I get this error:

Trying to get property 'projectvouchertype' of non-object

How can I change the select to use the releationship again?

Dec
03
5 months ago
Activity icon

Started a new Conversation Get All Data From Two Tables

Good morning:

I have a model that looks like this:

    protected $casts = [
        'id' => 'integer',
        'description' => 'string',
        'internalname' => 'string',
        'isactive' => 'boolean',
        'created_at' => 'datetime',
        'created_by' => 'string',
        'updated_at' => 'datetime',
        'updated_by' => 'string',
        'deleted_at' => 'datetime'
    ];

    public function communicationtypeCompanies()
    {
        return $this->hasMany('\App\Models\CommunicationtypeCompany', 'communicationtype_id', 'id');
    }

    public function communicationtypeContacts()
    {
        return $this->hasMany('\App\Models\CommunicationtypeContact', 'communicationtype_id', 'id');
    }

Now I tried this:

        $mail = \App\Models\Communicationtype::select('id')->where('icon', '=', 'envelope')->get();
        foreach($mail as $id){
            dd(\App\Models\CommunicationtypeContact::select('communicationdata')->where('communicationtype_id', '=', $id->id)->get());
            dd(\App\Models\CommunicationtypeCompanie::select('communicationdata')->where('communicationtype_id', '=', $id->id)->get());
        }

That works, but what I want to ask, are there a better a nicer way in Laravel to get the communicationdata from both tables that fetch the communicationtype_id from Communicationtype that have the icon envelope