maltekiefer

Software Engineer at Germany

Member Since 6 Months Ago

Experience Points
3,470
Total
Experience

1,530 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
21
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
3,470 XP
Jan
14
1 week 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
1 month 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
1 month 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
1 month 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
1 month 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
1 month 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
1 month 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

Sep
21
4 months ago
Activity icon

Replied to API Not Working With Laravel 8

It was the validation. I do this now:

    public function setClient (Request $request){

 /*       $request->validate([
            'pushtoken' => 'required|string',
            'allownotification' => 'required|boolean'
        ]);
**/
        $client = Clients::updateOrCreate(
            ['pushtoken' => $request->pushtoken],
            ['allownotification' => $request->allownotification]
        );

        return response()->json(null, 200);
    }

But then I get this error:

Illuminate\Database\Eloquent\MassAssignmentException: Add [pushtoken] to fillable property to allow mass assignment on [App\Models\Clients]. in file /Users/maltekiefer/Entwicklung/uadblock/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php on line 354

I send with Postman this in the body:

https://i.imgur.com/HJybEJw.png

Activity icon

Replied to API Not Working With Laravel 8

This is my web.php

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

Auth::routes([
    'register' => false, // Registration Routes...
    'reset' => false, // Password Reset Routes...
    'verify' => false, // Email Verification Routes...
]);

Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');

And I call this route:

http://127.0.0.1:8000/api/setClient

Sep
20
4 months ago
Activity icon

Started a new Conversation API Not Working With Laravel 8

Good morning,

in my api routes I have this:

Route::post('/setClient', 'App\Http\Controllers\[email protected]');

The method looks like this:

    public function setClient (Request $request){

        $request->validate([
            'pushtoken' => 'required|string',
            'allownotification' => 'required|boolean'
        ]);

        $client = Clients::updateOrCreate(
            ['pushtoken' => $request->pushtoken],
            ['allownotification' => $request->allownotification]
        );

        return response()->json(null, 200);
    }

But when I tried to make a post request with Postman I only see the home page in the response and in the database is nothing. When I change post to get in the route and open it in the browser I was instantly redirected to /.

Sep
11
4 months ago
Activity icon

Replied to Optional Parameter With Route Name

Ok. I fixed it too. Was something different, I override $mailbox in the class. Sorry

Activity icon

Replied to Optional Parameter With Route Name

See Obove, I edti my answer

Activity icon

Replied to Optional Parameter With Route Name

Is this not correct?

http://127.0.0.1:8000/apps/mail/?mailbox=MAIL_DEFAULT_FOLDER_SENT

When I do it like this, it works:

<a href="{{ url('/apps/mail/MAIL_DEFAULT_FOLDER_SPAM') }}" class="list-group-item">
Activity icon

Started a new Conversation Optional Parameter With Route Name

Hello,

I have this route:

Route::get('/apps/mail/{mailbox?}', '[email protected]')->name('mail.index');

My Controller looks like this:

    public function index($mailbox = 'MAIL_DEFAULT_FOLDER_INBOX')
    {

In my blade file I make this:

<a href="{{ route('mail.index', ['mailbox' => 'MAIL_DEFAULT_FOLDER_SPAM']) }}"

But then the URL looks like this:

http://127.0.0.1:8000/apps/mail?mailbox=MAIL_DEFAULT_FOLDER_SENT

How can I fix it that it works correctly?

Sep
10
4 months ago
Activity icon

Replied to Is This A Safe Way To Send Files?

Ok, I mean safe in the way to crash my app. Can a user crash my app when he is using the upload function?

Activity icon

Started a new Conversation Is This A Safe Way To Send Files?

Hello,

I have a general question. I have a form, where people can send a mail with attachments, multiple. When I send the mail, I do this to add the attachments to the mail:

            if($request->hasFile('attachments')){
                foreach ($request->attachments as $file) {
                    $mail->addAttachment($file->getRealPath(), $file->getClientOriginalName());
                }
            }

This is working, but my question is, is this a safe way to send attachments, or should I do a different way? Thanks

Aug
27
4 months ago
Activity icon

Replied to How To Understand Pivot?

Oh man, I forget ->get() I am sorry it is working

Activity icon

Replied to How To Understand Pivot?

OK. I tried it like this:

    public function getNotesByUser($id)
    {
        $notes = Note::whereHas('host', function($query) use ($id) {
            $query->where('enduser_id', $id);
        });

        return response()->json($notes);

    }

The model notehas this:

    public function host()
    {
        return $this->belongsTo('\App\Models\Host', 'host_id', 'id');
    }

But the return is empty. But there are notes for the host for the enduser

Activity icon

Started a new Conversation How To Understand Pivot?

Hello guys,

I hope you can help me to understand pivot tables. Currently, I am in a situation where I think I need pivot tables.

I have three tables, one called enduser, one hosts and the last one notes.

hosts have 1 FK enduser_id

notes have 1 FK hosts_id

Now I want to get all notes with the enduser id. So in the normal SQL I would go this way:

SELECT * FROM notes WHERE hosts_ID IN (SELECT id FROM hosts WHERE enduser_id = :id)

How can I make this call in a Laravel way? Is this really pivot?

Activity icon

Replied to Error Class Not Found Only In Production

Oh man. You are right. Sorry that I was so blind.

Activity icon

Started a new Conversation Error Class Not Found Only In Production

Good Morning, I have a model like this:

<?php
/**
 * Model object generated by: Skipper (http://www.skipper18.com)
 * Do not modify this file manually.
 */

namespace App\Models\AbstractModels;

use Illuminate\Database\Eloquent\Model;

abstract class AbstractNote extends Model
{
    /**  
     * Primary key type.
     * 
     * @var string
     */
    protected $keyType = 'bigInteger';
    
    /**  
     * The attributes that should be cast to native types.
     * 
     * @var array
     */
    protected $casts = [
        'id' => 'integer',
        'host_id' => 'integer',
        'notetype_id' => 'integer',
        'note' => 'string',
        'created_at' => 'datetime',
        'created_by' => 'string',
        'updated_at' => 'datetime',
        'updated_by' => 'string',
        'deleted_at' => 'datetime'
    ];
    
    public function host()
    {
        return $this->belongsTo('\App\Models\host', 'host_id', 'id');
    }
    
    public function notetype()
    {
        return $this->belongsTo('\App\Models\notetype', 'notetype_id', 'id');
    }
}

When I run it local everything works. But when I put it on my production server, I get this error:

[2020-08-27 06:30:05] local.ERROR: Class '\App\Models\notetype' not found {"userId":2,"exception":"[object] (Error(code: 0): Class '\App\Models\
otetype' not found at /srv/inventorix-backend/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php:745)

But I have the \App\Models\notetype file with this content:

<?php
namespace App\Models;

use App\Models\AbstractModels\AbstractNotetype;

class Notetype extends AbstractNotetype
{
}

And the abstract Model looks like this:

<?php
/**
 * Model object generated by: Skipper (http://www.skipper18.com)
 * Do not modify this file manually.
 */

namespace App\Models\AbstractModels;

use Illuminate\Database\Eloquent\Model;

abstract class AbstractNotetype extends Model
{
    /**  
     * Primary key type.
     * 
     * @var string
     */
    protected $keyType = 'bigInteger';
    
    /**  
     * The attributes that should be cast to native types.
     * 
     * @var array
     */
    protected $casts = [
        'id' => 'integer',
        'type' => 'string',
        'created_by' => 'string',
        'created_at' => 'datetime',
        'updated_by' => 'string',
        'updated_at' => 'datetime'
    ];
    
    public function notes()
    {
        return $this->hasMany('\App\Models\note', 'notetype_id', 'id');
    }
}

I don't get error... And again only in production

Aug
26
4 months ago
Activity icon

Started a new Conversation Passed A Var To Second Query

Hi,

I have a query like this:

    public function getInstalledHostsSoftwareProduct($id)
    {
        $data = Host::whereNull('deleted_at')->whereHas('softwarelicense', function ($query, $id) {return $query->where('softwareproduct_id', '=', $id);})->with('hosttype')->with('manufacturer')->with('office.site')->with('enduser')->get();
        return response()->json($data);
    }

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

ArgumentCountError
Too few arguments to function

This is my route:

Route::get('/getInstalledHostsSoftwareProduct/{id}', '[email protected]')->where('id', '[0-9]+');

What is my mistake here?

Aug
25
4 months ago
Activity icon

Started a new Conversation Vuetify Onchange Put Items Name To A Var

I have a v-select that looks like this:

    <v-select
      v-model="editedItem.site_id"
      :items="sites"
      label="Sites"
      item-text="name"
      item-value="id"
    ></v-select>

The sites items look like this:

0:
    city: (...)
    client: Object
        created_at: "2020-08-20T11:11:12.000000Z"
        created_by: "Malte Kiefer"
        deleted_at: null
        id: 1
        name: "Lemmer"
        updated_at: "2020-08-24T03:53:39.000000Z"
        updated_by: "Malte Kiefer"
    client_id: (...)
    country: (...)
    country_id: (...)
    created_at: (...)
    created_by: (...)
    deleted_at: (...)
    id: (...)
    name: (...)
    office: (...)
    street: (...)
    updated_at: (...)
    updated_by: (...)
    zipcode: (...)

So now I want to put the on a @change event the sites.client.name in the var. What is here the best way?

I tried this:

<v-select
  v-model="editedItem.site_id"
  :items="sites"
  label="Sites"
  item-text="name"
  item-value="id"
  @change="clientname = sites.client.name"
></v-select>

But I get the this error:

[Vue warn]: Error in v-on handler: "TypeError: Cannot read property 'name' of undefined"
Activity icon

Replied to Count On A Normal Get

I must count in the table Softwarelicense where the foreign key softwareproduct_id is

Activity icon

Replied to Count On A Normal Get

But I must count in a different table.

Activity icon

Started a new Conversation Count On A Normal Get

Hallo,

I have a method to get the entries in the database like this:

    public function getAll()
    {
        $data = Softwareproduct::with('manufacturer')->orderBy('name', 'asc')->get();

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

Now I have a second table, that includes all installed products like this:

<?php

namespace App\Models\AbstractModels;

use Illuminate\Database\Eloquent\Model;

abstract class AbstractSoftwarelicense extends Model
{
    /**
     * Primary key type.
     *
     * @var string
     */
    protected $keyType = 'bigInteger';

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'id' => 'integer',
        'host_id' => 'integer',
        'softwareproduct_id' => 'integer',
        'version' => 'string',
        'serial' => 'string',
        'username' => 'string',
        'passphrase' => 'string',
        'note' => 'string',
        'invoiceno' => 'string',
        'created_at' => 'datetime',
        'created_by' => 'string',
        'updated_at' => 'datetime',
        'updated_by' => 'string'
    ];

    public function host()
    {
        return $this->belongsTo('\App\Models\Host', 'host_id', 'id');
    }

    public function softwareproduct()
    {
        return $this->belongsTo('\App\Models\Softwareproduct', 'softwareproduct_id', 'id');
    }
}

Is there a simple way to get the count of the installation products with the getAll method too?

    public function getAll()
    {
        $data = Softwareproduct::with('manufacturer')->orderBy('name', 'asc')->get();

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

Replied to Get Data From Relationsship

Thanks. That works

Activity icon

Started a new Conversation Get Data From Relationsship

Hello,

I have a model with the name site like this:

<?php
/**
 * Model object generated by: Skipper (http://www.skipper18.com)
 * Do not modify this file manually.
 */

namespace App\Models\AbstractModels;

use Illuminate\Database\Eloquent\Model;

abstract class AbstractSite extends Model
{
    /**
     * Primary key type.
     *
     * @var string
     */
    protected $keyType = 'bigInteger';

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'id' => 'integer',
        'name' => 'string',
        'client_id' => 'integer',
        'country_id' => 'integer',
        'street' => 'string',
        'zipcode' => 'string',
        'city' => 'string',
        'created_at' => 'datetime',
        'created_by' => 'string',
        'updated_at' => 'datetime',
        'updated_by' => 'string'
    ];

    public function country()
    {
        return $this->belongsTo('\App\Models\Country');
    }

    public function client()
    {
        return $this->belongsTo('\App\Models\Client', 'client_id', 'id');
    }

    public function office()
    {
        return $this->hasMany('\App\Models\Office', 'site_id', 'id');
    }
}

Then I have an office model like this:

<?php
/**
 * Model object generated by: Skipper (http://www.skipper18.com)
 * Do not modify this file manually.
 */

namespace App\Models\AbstractModels;

use Illuminate\Database\Eloquent\Model;

abstract class AbstractOffice extends Model
{
    /**
     * Primary key type.
     *
     * @var string
     */
    protected $keyType = 'bigInteger';

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'id' => 'integer',
        'site_id' => 'integer',
        'name' => 'string',
        'created_at' => 'datetime',
        'created_by' => 'string',
        'updated_at' => 'datetime',
        'updated_by' => 'string'
    ];

    public function site()
    {
        return $this->belongsTo('\App\Models\Site', 'site_id', 'id');
    }

    public function host()
    {
        return $this->hasMany('\App\Models\Host', 'office_id', 'id');
    }
}

To get my offices I have a methode thats give me the fowlling data:


$data = Office::with('site')->get();

Is it possible to get it with the client data from the site table? Thanks

Aug
18
5 months ago
Activity icon

Started a new Conversation Get Username On Vue.js Ajax Post Request / Auth With The API

Hello,

I have the create method in my controller. There I have the following so far:

$salutation->created_by = Auth::user()->name;

But now it does not work if I make the call with Vue.js:

    onSubmitSalutation(evt) {
        evt.preventDefault()
        this.errors = {};
        axios.post('/api/postSalutation', {
            description: this.description
        }).then(response => {
            this.$bvModal.hide('createSalutation');
            this.getSalutations();
        }).catch(error => {
            if (error.response.status === 422) {
                this.errors = error.response.data.errors || {};
            }
        });
    },

So my question is, how can I send the username, or even better authenticate myself for the API, so that I can use the middelware:

Route::group(['middleware' => ['auth']], function () {
    Route::post('/postSalutation', 'SalutationsControl[email protected]');
});
Activity icon

Replied to Frontend JQuery And Backend Laravel Ist That The Best Way

Never used it before. Isn‘t still JS Ajax requests

Activity icon

Replied to Frontend JQuery And Backend Laravel Ist That The Best Way

How can I do the component-based approach, where each section on the page is separated non-render-blocking component.

Activity icon

Started a new Conversation Frontend JQuery And Backend Laravel Ist That The Best Way

I would like to know how you approach this or what your opinion is about the right solution.

At the moment I am thinking about implementing a project for me as follows:

  • Using Laravel for routes and views
  • Use jQuery in the frontend for all requests (PUT, POST, DELETE, UPDATE, SHOW)
  • accordingly in the backend an API, which then processes all jQuery requests

Or maybe it's better to do it this way:

Laravel for routes, views and displaying the data and then just use jQuery to manipulate the data. Why I ask,

Currently I have a form where the user can enter data for a computer:

  • Name
  • IP
  • Manufacturer

Now manufacturer is a select. Next to it there is a button Add, which opens a modal and allows a user to add a manufacturer. After sending the modal via jQuery and a successful return value, I insert the new vendor into the select via jQuery and select it directly.

Translated with www.DeepL.com/Translator (free version)

Jul
24
5 months ago
Activity icon

Started a new Conversation Vue

Hello,

I created an autocomplete for a layout, like this:

<template>
 <div>
  <input type="text" placeholder="what are you looking for?" v-model="query" v-on:keyup="autoComplete" class="form-control">
  <div class="panel-footer" v-if="results.length">
   <ul class="list-group">
    <li class="list-group-item" v-for="result in results">
     {{ result.description }}
    </li>
   </ul>
  </div>
 </div>
</template>
<script>
 export default{
  data(){
   return {
    query: '',
    results: []
   }
  },
  methods: {
   autoComplete(){
    this.results = [];
    if(this.query.length > 2){
     axios.get('/search',{params: {query: this.query}}).then(response => {
      this.results = response.data;
     });
    }
   }
  }
 }
</script>

Now I want, when I click on the search result, that the result is added to a div. I know how to do it in jQuery but how can I make it in Vue?

Jul
23
5 months ago
Activity icon

Replied to Cleaner And Better Solution Possible?

Sorry of course. I just want to know if this is the correct way in the view.

Activity icon

Replied to Cleaner And Better Solution Possible?

Ok last question for clean code. Currently, I make it like this:

    public function create()
    {
        return view('sites.create', [
            'countries' => Country::all(),
            'clients' => Client::all(),
        ]);
    }

It is the method for the sites create view. In the view I did this:

                                    @foreach ($countries as $country)
                                        <option value="{{ $country->id }}">{{ $country->name }} [{{ $country->abbreviation }}]</option>
                                    @endforeach
Activity icon

Replied to Cleaner And Better Solution Possible?

Ok. Now it works, but why this:

use App\Sites;
use App\Models\Site;

What have I done wrong that this happens?

Activity icon

Replied to Cleaner And Better Solution Possible?

>>> \App\Models\Site::first()->country
=> App\Models\Country {#4049
     id: "1",
     name: "Germany",
     abbreviation: "GER",
     created_at: "2020-07-23 07:34:13",
     created_by: null,
     updated_at: "2020-07-23 08:05:55",
     updated_by: null,
   }
>>>
Activity icon

Replied to Cleaner And Better Solution Possible?

[email protected]
> php artisan tinker                                                                                                                                                                                                                                    inven
Psy Shell v0.10.4 (PHP 7.4.8 — cli) by Justin Hileman
>>> \App\Models\Country::first()->sites
=> Illuminate\Database\Eloquent\Collection {#4041
     all: [
       App\Models\Site {#4048
         id: "1",
         name: "Lohmar",
         client_id: "1",
         country_id: "1",
         street: "Straße 1",
         zipcode: "12345",
         city: "Lohmar",
         created_at: "2020-07-23 08:23:45",
         created_by: null,
         updated_at: "2020-07-23 08:23:45",
         updated_by: null,
       },
     ],
   }
>>>

Site.php

<?php
namespace App\Models;

class Site extends \App\Models\AbstractModels\AbstractSite
{

}

AbstractSite.php

<?php
/**
 * Model object generated by: Skipper (http://www.skipper18.com)
 * Do not modify this file manually.
 */

namespace App\Models\AbstractModels;

use Illuminate\Database\Eloquent\Model;

abstract class AbstractSite extends Model
{
    /**
     * Primary key type.
     *
     * @var string
     */
    protected $keyType = 'bigInteger';

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'id' => 'integer',
        'name' => 'string',
        'client_id' => 'integer',
        'country_id' => 'integer',
        'street' => 'string',
        'zipcode' => 'string',
        'city' => 'string',
        'created_at' => 'datetime',
        'created_by' => 'string',
        'updated_at' => 'datetime',
        'updated_by' => 'string'
    ];

    public function country()
    {
        return $this->belongsTo('\App\Models\Country');
    }

    public function client()
    {
        return $this->belongsTo('\App\Models\client', 'client_id', 'id');
    }

    public function office()
    {
        return $this->hasMany('\App\Models\office', 'site_id', 'id');
    }
}

Activity icon

Replied to Cleaner And Better Solution Possible?

Sorry, I am new at Laravel, where should I put this?

Activity icon

Replied to Cleaner And Better Solution Possible?

We use the app Skipper18, that's created our models. Here is the model Country.php

<?php
namespace App\Models;

class Country extends \App\Models\AbstractModels\AbstractCountry
{

}

And here is the file AbstractCountry.php

<?php
/**
 * Model object generated by: Skipper (http://www.skipper18.com)
 * Do not modify this file manually.
 */

namespace App\Models\AbstractModels;

use Illuminate\Database\Eloquent\Model;

abstract class AbstractCountry extends Model
{
    /**
     * Primary key type.
     *
     * @var string
     */
    protected $keyType = 'bigInteger';

    /**
     * The model's default values for attributes.
     *
     * @var array
     */
    protected $attributes = [
        'created_at' => 'DB::raw("CURRENT_TIMESTAMP")',
        'updated_at' => 'DB::raw("CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP")'
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'id' => 'integer',
        'name' => 'string',
        'abbreviation' => 'string',
        'created_at' => 'datetime',
        'created_by' => 'string',
        'updated_at' => 'datetime',
        'updated_by' => 'string'
    ];

    public function sites()
    {
        return $this->hasMany('\App\Models\Site');
    }
}

Activity icon

Replied to Cleaner And Better Solution Possible?

They are in the models folder:

> ls -Rl app/Models                                                                                                                                                                                                 inven RC=1
total 112
[email protected] 16 maltekiefer  staff  512 21 Jul 23:06 AbstractModels
[email protected]  1 maltekiefer  staff   96 21 Jul 23:06 Client.php
[email protected]  1 maltekiefer  staff   99 23 Jul 08:59 Country.php
[email protected]  1 maltekiefer  staff   98 21 Jul 23:06 Enduser.php
[email protected]  1 maltekiefer  staff   92 21 Jul 23:06 Host.php
[email protected]  1 maltekiefer  staff  108 21 Jul 23:06 Hostproperty.php
[email protected]  1 maltekiefer  staff  116 21 Jul 23:06 Hostpropertytype.php
[email protected]  1 maltekiefer  staff  100 21 Jul 23:06 Hosttype.php
[email protected]  1 maltekiefer  staff  108 21 Jul 23:06 Manufacturer.php
[email protected]  1 maltekiefer  staff   92 21 Jul 23:06 Note.php
[email protected]  1 maltekiefer  staff   96 21 Jul 23:06 Office.php
[email protected]  1 maltekiefer  staff  104 21 Jul 23:06 Salutation.php
[email protected]  1 maltekiefer  staff   93 23 Jul 08:59 Site.php
[email protected]  1 maltekiefer  staff  114 21 Jul 23:06 Softwarelicense.php
[email protected]  1 maltekiefer  staff  114 21 Jul 23:06 Softwareproduct.php

app/Models/AbstractModels:
total 112
[email protected] 1 maltekiefer  staff   921 21 Jul 23:06 AbstractClient.php
[email protected] 1 maltekiefer  staff  1074 23 Jul 09:38 AbstractCountry.php
[email protected] 1 maltekiefer  staff  1164 21 Jul 23:06 AbstractEnduser.php
[email protected] 1 maltekiefer  staff  2038 21 Jul 23:06 AbstractHost.php
[email protected] 1 maltekiefer  staff  1027 21 Jul 23:06 AbstractHostproperty.php
[email protected] 1 maltekiefer  staff   898 21 Jul 23:06 AbstractHostpropertytype.php
[email protected] 1 maltekiefer  staff   840 21 Jul 23:06 AbstractHosttype.php
[email protected] 1 maltekiefer  staff   955 21 Jul 23:06 AbstractManufacturer.php
[email protected] 1 maltekiefer  staff   831 21 Jul 23:06 AbstractNote.php
[email protected] 1 maltekiefer  staff   947 21 Jul 23:06 AbstractOffice.php
[email protected] 1 maltekiefer  staff   822 21 Jul 23:06 AbstractSalutation.php
[email protected] 1 maltekiefer  staff  1160 23 Jul 09:39 AbstractSite.php
[email protected] 1 maltekiefer  staff  1192 21 Jul 23:06 AbstractSoftwarelicense.php
[email protected] 1 maltekiefer  staff  1019 21 Jul 23:06 AbstractSoftwareproduct.php
Jul
22
6 months ago
Activity icon

Replied to Cleaner And Better Solution Possible?

Ok, I tried it like this:

    public function country()
    {
        return $this->belongsTo('\App\Models\Country');
    }
    public function sites()
    {
        return $this->hasMany('\App\Models\Site');
    }

Still:

Call to undefined relationship [country] on model [App\Sites].

Fix the first letter

Activity icon

Replied to Cleaner And Better Solution Possible?

Ok, I have in my abstract models something like this:

#AbstractCountry.php

    public function site()
    {
        return $this->hasMany('\App\Models\site', 'country_id', 'id');
    }

#AbstractSite.php

    public function country()
    {
        return $this->belongsTo('\App\Models\country', 'country_id', 'id');
    }

In my view I make it like this:

<td>{{ $site->country->name ?? '-' }}</td>

I always get the - now. This is my table layout:


        Schema::create('sites', function (Blueprint $table) {
            $table->bigInteger('id')->autoIncrement()->unsigned();
            $table->string('name', 255)->unique();
            $table->bigInteger('client_id')->nullable(true)->unsigned();
            $table->bigInteger('country_id')->nullable(true)->unsigned();
            $table->string('street', 255)->nullable(true);
            $table->string('zipcode', 10)->nullable(true);
            $table->string('city', 255)->nullable(true);
            $table->timestamp('created_at')->nullable(true);
            $table->string('created_by', 255)->nullable(true);
            $table->timestamp('updated_at')->nullable(true);
            $table->string('updated_by', 255)->nullable(true);
        });

When I use this in the controller:

'sites' => Sites::with('country')->get(),

I get this error:

Call to undefined relationship [country] on model [App\Sites].

Activity icon

Started a new Conversation Cleaner And Better Solution Possible?

Hello,

currently, I have an index view that I call over the controller like this:

    public function index()
    {
        return view('sites.index', [
            'sites' => Sites::all(),
        ]);
    }

Inside the view I did this:

                    @foreach ($sites as $site)
                    <tr>
                        <td>{{ $loop->iteration }}</td>
                        <td>{{ $site->name }}</td>
                        <td>{{ $site->street }}, {{ $site->zipcode }} {{ $site->city }}</td>
                        <td>
                            <?php
                                $country = \App\Countries::find($site->country_id);
                            ?>
                            {{ $country->name }}
@endforeach

My question is, is this part really a good and clean solution or is there a better way:

                            <?php
                                $country = \App\Countries::find($site->country_id);
                            ?>
                            {{ $country->name }}