ettore

ettore

Member Since 1 Year Ago

Oslo

Web Developer at E2 Consult

Experience Points 47,130
Experience Level 10

2,870 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 420
Lessons
Completed
Best Reply Awards 8
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.

13 Apr
3 months ago

ettore left a reply on Prefix Views

Hi.

Looking at the view helper functions, i guess you could create your own as it first checks if you have view function, this way you could use multiple directories and namespaces. ´´´ if (! function_exists('view')) {

´´´

What if you try create this global helper function:

´´´ function view($view = null, $data = [], $mergeData = [], $prefix = 'admin') { $factory = app(ViewFactory::class);

    if (func_num_args() === 0) {
        return $factory;
    }

    return $factory->make($prefix . '.'. $view, $data, $mergeData);

} ´´´

ettore left a reply on Prefix Views

Hi.

looking at the view helper, i guess you could create your own as it first checks if you have view function

´´´ if (! function_exists('view')) {

´´´

What if you try create this global helper function:

´´´ function view($view = null, $data = [], $mergeData = [], $prefix = 'admin') { $factory = app(ViewFactory::class);

    if (func_num_args() === 0) {
        return $factory;
    }

    return $factory->make($prefix . '.' . $view, $data, $mergeData);
}

} ´´´

25 Mar
3 months ago

ettore left a reply on When To Use Vue Instead Of Laravel ?

There is no rule, it depends on what you want to do! Laravel does things on the server side, and Vue does things on the browser/users side.

23 Mar
3 months ago

ettore left a reply on DropboxServiceProvider.php Throws Undefined Index In $client Line .

@FAROOQ - Does it work if you are doing (just for test):

'dropbox' => [
        'driver' => 'dropbox',
        'app_secret' => 'xwylhl1ho4u02ia',
        'token' => '-cCZhqTAqjAAAAAAAAAIIsqki9W5PVEG3eBQqcCKzJ5lqyjfqS-JH6S2xGMUEgpE'
    ],
''

If that works then you are not using your .env file correctly https://laravel.com/docs/5.5/helpers#method-env

22 Mar
3 months ago

ettore left a reply on Sum Returns Double Value

You could just do it as a separate query where you just do the one join. That probably will let you sleep easier at night knowing that you got full control ;)

ettore left a reply on DropboxServiceProvider.php Throws Undefined Index In $client Line .

@FAROOQ - Are you positive you got you casing correct?

ettore left a reply on DropboxServiceProvider.php Throws Undefined Index In $client Line .

From the docs: The resolver Closure must return an instance of League\Flysystem\Filesystem. The $config variable contains the values defined in config/filesystems.php for the specified disk.

From what I understand, you need it to match your config/filesystems.php file so that your token is passed into the DropboxClient constructor.

The error tells you that you are looking for an array index that doesn't exist. You could try to dd($config)

ettore left a reply on DropboxServiceProvider.php Throws Undefined Index In $client Line .

Did you try:

$config['authorization_token']

ettore left a reply on Link In Header File Always Returns To The Home Page

Cool, glad you fixed it, I just read your response now after posting my last reply

ettore left a reply on Link In Header File Always Returns To The Home Page

Try;:


Route::get('/abc', function () {
    dd('hello');
});

ettore left a reply on Link In Header File Always Returns To The Home Page

Okey, does that route require a logged in user? Did you make sure it is not the Auth that is redirecting you to the home page?

ettore left a reply on Link In Header File Always Returns To The Home Page

Hmmm, are you positive that you are one the view that you think you are?

ettore left a reply on Link In Header File Always Returns To The Home Page

Can be a typo somwhere in files.

You could try using a named route:

<a href="{{ route('abc') }}">

ettore left a reply on Sum Returns Double Value

@ATFINHO - You can try

>leftJoin('car_maintenance','car_maintenance.car_id','=','cars.id')

It's very difficult to give advice when we don't know the column names

ettore left a reply on Organise Controllers, Routes, Views

You should check out Jeffreys series

https://laracasts.com/series/build-a-laravel-app-with-tdd

It is based on projects, tasks and users, the same models that you are planning on working with. I bet it will help you solve you problems.

ettore left a reply on Sum Returns Double Value

Do you mean that the values that is returned is 2 times the expected value? I would try to rund this in Sequel Pro, TablePlus or something to see what is returned.

Probably something is wrong/missing in your groupBy statements

ettore left a reply on How To Access Data In Nested / Multi Dimensional Array In Vue File ?

It seems like you are not loading the author model on the blogs in your controller.

Adding with('author') should probably solve the problem.

return Blog::with('author')->get();

ettore left a reply on Can I Minify This Code?

@BEHNAMPMDG3 - Cool, I suggest you get it again.

ettore left a reply on How To Give Page Numbers For Printout In Barryvdh/laravel-dompdf

Cool, what i suggest is that you see how many orders that will fit on a single page. If your page fits 5 orders, then you would split a collection of 20 orders into 4 chunks of 5 orders within each, as that helper function will let you do.

Then you can create your template as i suggested above with you header, body (5 orders) and footer (page number) at choosing.

Can then pass into every page the page number as a $page variable that you use. Look at this page if you are unsure of how to use the incldue method with variables passed in: https://laravel.com/docs/5.8/blade#including-sub-views

21 Mar
3 months ago

ettore left a reply on I'm Having Trouble Understanding The MorphMany Relationship

@CHRISGRIM - Hi.

Did you create a method on the Favorite model that gets the target?

    public function favorited()
    {
        return $this->morphTo();
    }

You can then get a users favorites like you have done, then on the favorite model you can use the above method to get the event.

You should use use the method described in this video: https://laracasts.com/series/eloquent-relationships/episodes/5

ettore left a reply on How To Set Multiple Domain Names On 1 Nginx Server ?

Yes, and did you create the record set inside that hosted zone, and make them point to your server? Every record is the url you want to point to you server.

Then you just set up normal serverblocks like described in that guide ;)

ettore left a reply on Associating Models

Ok, you can't do?

    private function fillDealerships(array $files)
    {
        foreach ($files as $file) {
            $data = $this->getFileContent($file);

            foreach ($data as $item) {
                $slug = isset($item['u']) ? Str::slug($item['u']) : $file['filename'];
                $filename = $file['filename'];

                $dealership = Dealership::updateOrCreate([
                    'slug' => $slug,
                ], [
                    'name' => $item['n'] ?? $slug,
                ]);

                $brand = Brand::firstOrCreate(['name' => $filename]);
                $dealership-> brands()->syncWithoutDetaching($brand);
            }
        }
    }

ettore left a reply on Associating Models

Ah, okey. If you know what brand it is based on the filename then you can do something more like this:

$brand = Brand::where('name', $filename)->first();
$dealership->brands()->syncWithoutDetaching($brand);

ettore left a reply on Associating Models

Hmm, not quite sure what you are doing here. If you are going to use the sync method then you need you brands model/id that you want to have attached. How are you finding the brands, do you look up based on the filename?

Or do you plan on attaching all the brands in the database (based on your last code)?

ettore left a reply on Associating Models

You can do this:

$dealership-> brands()->syncWithoutDetaching($brand);

ettore left a reply on Update Custom Pivot Model "SQLSTATE[HY093]: Invalid Parameter Number: Parameter Was Not Defined"

Since you are dealing with composite keys, then you could add it as a trait "hasCompositeKeys" that you implement on the models needing it. It would make you model cleaner

ettore left a reply on Authorize In Crud Controller

You write it where you want to authorize the user. So if you want to do the check on both methods, then you do that.

ettore left a reply on Update Custom Pivot Model "SQLSTATE[HY093]: Invalid Parameter Number: Parameter Was Not Defined"

@JULIEN44 - Well, you need to be able to locate the row you want to update, and account_id and event_id is probably you primary key on that table?

ettore left a reply on Update Custom Pivot Model "SQLSTATE[HY093]: Invalid Parameter Number: Parameter Was Not Defined"

From the documentation:

Updating A Record On A Pivot Table If you need to update an existing row in your pivot table, you may use updateExistingPivot method. This method accepts the pivot record foreign key and an array of attributes to update:

$user = App\User::find(1);

$user->roles()->updateExistingPivot($roleId, $attributes);

ettore left a reply on App Debug Not Working In Laravel 5.8

Did you update all the composer packages?

ettore left a reply on Resize Images In Laravel

You could check out Intervention - https://github.com/Intervention/image

and

Spaties Laravel Image Optimizer - https://github.com/spatie/laravel-image-optimizer

I use both ;)

ettore left a reply on Can I Minify This Code?

Hey.

Jeffrey goes into this in detail in his videos, you should take a look there first as this is well documented in the Laravel documentation and thoroughly explained in his series ;)

For example look at this one (uses a policy around 15 min into the video) https://laracasts.com/series/build-a-laravel-app-with-tdd/episodes/16

Good luck!

20 Mar
3 months ago

ettore left a reply on Homebrew PHP 7.2 ARGON2i

@CHRISTOPHER - Okey, i get what you are saying. Seems like you need to follow theese steps https://stackoverflow.com/questions/51383867/how-to-compile-php-using-with-password-argon2

ettore left a reply on How Search For Multiple Words In Eloquent?

Hmmm, you need to think out some hacky way to do this. I guess I would explode the query-string on every space and look with a new LIKE-query for every word in the array you get, kind of like you did above.

Hope it helps ;)

ettore left a reply on ErrorException: Undefined Property: Illuminate\Foundation\Bus\PendingDispatch::$connection

Are you sure you are chaining the jobs correctly? I've never done it before, but if you don't mind me guessing:

GenerateSurveyFeedbackReportForUser::withChain([
   SendReportToParticipant::dispatch($userId, $absolutePDFPath)
])->dispatch($userId, $absolutePDFPath, true);

The Dispatchable trait that hold the withChain method seems to return an instance of PendingChain class, and the dispatch method on PendingChain class takes to arguments.

I see that the withChain method in the documentation accepts a new instance of the job https://laravel.com/docs/5.5/queues#job-chaining

Maybe you can try something similar to this ?


GenerateSurveyFeedbackReportForUser::withChain([
   new SendReportToParticipant($userId, $absolutePDFPath)
])->dispatch();

ettore left a reply on How To Set Multiple Domain Names On 1 Nginx Server ?

You find Route 53 here: https://console.aws.amazon.com/route53/home

Thats where you do the DNS management. When you are satisfied with your domains and all pointing to your server, then you can set up the server blocks from the digital ocean guide i posted in my last reply.

Another option if you dont have domain is to set up NGINX to respond to different ports, so that you request get channeled to a specific port on the server, then you can make NGINX respond to that port. You might have to update your AWS Security Groups to allow communication on that port if you do it this way.

ettore left a reply on Can I Minify This Code?

Look at this video https://laracasts.com/series/build-a-laravel-app-with-tdd/episodes/4

User route model binding:


public function members(Course $course)
    {
        $members = $course->members;
        return view('members.show', ['members' => $members, 'course'=>$course]);    
    }

ettore left a reply on What Is The Best Solution To Import List Of Customers To This Table?

I agree with @stereoh.

As I already do somthing similar to what you need I will share my code with you. I use it to process 50.000 lines in a CSV.

    $file = "xxxxxx.csv";
        if ($handle = fopen($file, "r")) {
            $headers = collect(fgetcsv($handle, 0, ";"));
            while (($data = fgetcsv($handle, 0, ";")) !== FALSE) {
                $member = $headers->combine(collect($data));

        // Do you thing, I use a seperate method for cleaner code
                $this->importAndStuff($member);
            }
            fclose($handle);
        }

ettore left a reply on Retrieving Files From Storage

Hi.

I made a custom File model, with some handy methods, maybe you can get some of them to work


    public static $folder = 'files';
    public static $disk = 's3';

    public function getAbsolutePathAttribute()
    {
        return Storage::disk(self::$disk)->path($this->filepath);
    }

    public function getContent()
    {
        return Storage::disk(self::$disk)->get($this->filepath);
    }

    public function downloadContent()
    {
        return Storage::disk(self::$disk)->download($this->filepath);
    }

    public function getFile()
    {
        return new \Illuminate\Http\File($this->absolute_path);
    }

ettore left a reply on Can I Use Model Function Or Relationship Inside Eloquent?

Do it like @ftiersch suggests or you could get all the models and then filter it down using the filter method:

https://laravel.com/docs/5.5/collections#method-filter


$orders = Order::all()->filter(function($order){
    return $order->total_cost() > request('input');
});

ettore left a reply on Is It Possible To Put Model And Controller Files In Subfolders?

Hi.

I put the models in a foder named app\Models\

All you need to do is update the namespace in every model, and where they are used other places in you app, so that the system finds (the most timeconsuming task). If you decide to move the User model then you also want to update the config/auth file: ´´´ 'providers' => [ 'users' => [ 'driver' => 'eloquent', 'model' => App\Models\User::class, ], ´´´

For the Controller you are extending the Controller class, so you need to import the "App\Http\Controllers\Controller" class when you are not in the same namespace anymore.

ettore left a reply on How To Give Page Numbers For Printout In Barryvdh/laravel-dompdf

Hey.

What if you split up $orderlists to chunks that is of the size of a page and use the chunk key as page number?

Then every chunk could be a page and you could include your header in the beginning of new page. End then you finish every page with the

with the CSS .page-break { page-break-after: always; }

I would create the template from the above like "page.blade.php" and rund the chunks on the template file

@foreach($chunks as $key => $chunk) @include("page", ['page' => $key + 1, $dataset => $chunk] @endforeach

ettore left a reply on SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column '0' In 'field List'

Hei.

Are you running it on a Collection?

Maybe try CmsPage::where(['id'=>$id])->first()->update(['status'=>$status,'title'=>$data['title'], 'url'=>$data['url'],'description'=>$data['description']]);

ettore left a reply on How To Set Multiple Domain Names On 1 Nginx Server ?

Hi.

I'm running a server on AWS with multiple domains. What I did was set up a hosted zone in Route 53 in AWS with the domain pointing to correct IP. I have several sub-domains also set up there pointing to different server blocks.

Then i just followed this guide: https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-16-04

Worked like a charm!