bestmomo

bestmomo

Member Since 4 Years Ago

Toulouse, France

Experience Points 357,640
Experience Level 50

0 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 19
Lessons
Completed
Best Reply Awards 406
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.

06 Dec
2 months ago

bestmomo left a reply on Administration

Thank you fort interesting answers but my initial question is on code organisation :)

bestmomo left a reply on Auth::user(); Authentication In Core Php

I made something with Laravel 5.2 to use it with code PHP :

require getcwd() . '/../../../../bootstrap/autoload.php'; // Adapt to your path
$app = require_once getcwd() . '/../../../../bootstrap/app.php';
$kernel = $app->make('Illuminate\Contracts\Http\Kernel');
$response = $kernel->handle(
  $request = Illuminate\Http\Request::capture()
);
$id = $app['encrypter']->decrypt($_COOKIE[$app['config']['session.cookie']]);
$app['session']->driver()->setId($id);
$app['session']->driver()->start();

Then you have Laravel in $app and use $app['auth'] I dont know if it still works with 5.7 version.

bestmomo left a reply on UPGRADE TO LARAVEL 5.7 FROM 5.4

For a clean upgrade install Laravel 5.7 and copy all files. Seems longer but you'll spend less time with bugs tracking ;)

05 Dec
2 months ago

bestmomo left a reply on Using Auth::user(); In Core Php

I made something with Laravel 5.2 to get Laravel app from core PHP :

require getcwd() . '/../../../../bootstrap/autoload.php';
$app = require_once getcwd() . '/../../../../bootstrap/app.php';
$kernel = $app->make('Illuminate\Contracts\Http\Kernel');
$response = $kernel->handle(
  $request = Illuminate\Http\Request::capture()
);
$id = $app['encrypter']->decrypt($_COOKIE[$app['config']['session.cookie']]);
$app['session']->driver()->setId($id);
$app['session']->driver()->start();

Dont know if it works with recent Laravel version but it's a way. You can use $app['auth'] for example.

bestmomo left a reply on Is This Good Approach To Have Own Service Provider?

There is no rule, make as you feel. Code organisation is a story of personal covenant unless the development is done by several people, so they have to agree...

bestmomo started a new conversation Administration

I have explored the available packages to facilitate the construction of an administration: Voyager, LaraAdmin, Backpack, Boilerplate (not Nova which is a paid solution and I code only for fun) and others ... But I can not satisfy myself and I ended almost systematically to create something in my own way ...

But whether it is a package or the personal code we end up with a transplant not necessarily well digested. I like the isolation of treatments because it makes things clearer. At the code level it's easy but when we reason more globally it becomes problematic.

So I thought after all why not completely distinguish frontend and backend with two separate installations of Laravel (or other)? The advantage of the package-specific separation is preserved without the inconvenience of code complexity and mandatory entanglements. It is also easy to reuse the code by enriching it with each project by providing optional features for example.

I think that I will adopt this approach for my next project but I would like to have your opinion on the subject ...

29 Sep
4 months ago

bestmomo left a reply on Array Combine Totals

Not sure to understand your question but array_merge is always working.

bestmomo left a reply on How To Pass Additional Parameters To Resource Class?

@alihoushyaripour

I made a test, you can add an attribute to your model and after send it to your resource. It works.

I made a simple UserResource and :

$user = User::find(1);
$user->test = 'ok';
$resource = new UserResource($user);
dd($resource);

I get that for the resource :

#attributes: array:12 [▼
      "id" => 1
      "name" => "Adam"

      ...

      "test" => "ok"
    ]

bestmomo left a reply on Is Bootstrap-multiselect Plugin Is Compatible With Bootstrap 4.1 ?

Maybe you can use this PR to make it work with Bootstrap 4.

bestmomo left a reply on Want To Access A Particular Array Element.

Could you show dd($data['Documents']) ?

bestmomo left a reply on Database Design / One To Many

  1. I would create a One To One relation between Image and Product (Image has one Product with foreign key on Product).

  2. I dont really understand, you load relation only if you use productImages().

bestmomo left a reply on SetLocale

Usually setLocale is set in a middleware.

bestmomo left a reply on How To Pass Additional Parameters To Resource Class?

Why not just add this to gift ?

$gift->from = 'PlaceController';

bestmomo left a reply on Route For Different User Types

Just send 2 parameters and update your middleware code. Look at documentation.

27 Sep
4 months ago

bestmomo left a reply on Append To And Modify Users Collection In Controller Before Pass It To View

Hello,

With your solution you send 3 queries to database, not really optimized. Maybe this kind of code is better :

$all = collect(User::all()->toArray());

$users = $all->where('competition1', 'yes')->map(function($item, $key) {
    $item['location'] = 'foo';
    return $item;
})->concat($all->where('competition2', 'yes')->map(function($item, $key) {
    $item['location'] = 'bar';
    return $item;
})->concat($all->where('competition3', 'yes')->map(function($item, $key) {
    $item['location'] = 'some';
    return $item;
})));

dd($users);
24 Sep
4 months ago

bestmomo left a reply on Query With Count And GroupBy

If you use Eloquent just do that :

$regios = App\Regio::withCount('inscricoes')->get();

bestmomo left a reply on Difference Between !== & !=

From manual :

$a !== $b Not identical TRUE if $a is not equal to $b, or they are not of the same type.

23 Sep
4 months ago

bestmomo left a reply on Property [id] Does Not Exist On This Collection Instance!!!!

Let's show some code. Maybe you try to get attribute on collection without iterate...

bestmomo started a new conversation Photos Gallery

For information I put on Github an example of a photo gallery.

It serves as the basis for a series of French turoriels on my blog.

17 Sep
4 months ago

bestmomo left a reply on Load Js Dependecy In My Bootstrap.js

Luckily there is something else that bootstrap and jquery :)

bestmomo started a new conversation Bug In Mix ?

Say in my resources/js/app.js I add a require for sweetalert :

window._ = require('lodash');
window.Popper = require('popper.js').default;
window.swal = require('sweetalert2');

So I launch npm run dev. My sweetalert is not loaded. But now if i change a bit :

window._ = require('lodash');
window.swal = require('sweetalert2');
window.Popper = require('popper.js').default;

It works !

I have tried with other libraries with same result...

Any idea ?

Thanks

11 Sep
5 months ago

bestmomo left a reply on Delete File From Dir With Unlink

@tykus

Even the core doesn't use the FileSystem ^^

In UpCommand Console command :

@unlink(storage_path('framework/down'));

bestmomo left a reply on Eloquent Get Insert Id

When you create a record with Eloquent you get the id in the model :

$flight = App\Flight::create(['name' => 'Flight 10']);
$id = $flight->id;

bestmomo left a reply on Route With Names Issue

When you use get you get a collection of elements and you must iterate, if you have only one element use first or firstOrFail.

10 Sep
5 months ago

bestmomo left a reply on Helper Function

Happy it works now ;)

bestmomo left a reply on [SOLVED]Requests Not Validating Contact Form

I suppose you use flash package, I never used it but did you installed it correctely ?

bestmomo left a reply on [SOLVED]Requests Not Validating Contact Form

Looks like I got the good answer above ^^

bestmomo left a reply on Helper Function

Do you use some contact variable on this page ?

bestmomo left a reply on Requests Not Validating Contact Form

Remove this line in ContactFormRequest :

use Illuminate\Foundation\Http\FormRequest;
//use App\Http\Controllers\ContactFormRequest;
use App\Mail\ContactEmail;
use Flash;

bestmomo left a reply on Helper Function

With this code you cant get Undefined variable contact...

bestmomo left a reply on Helper Function

Do you really use this code :

<?php

if (!function_exists ('sections')) {
    function sections()
    {
        return \App\Models\Section::all();
    }
}

if (!function_exists ('site_data')) {
    function site_data()
    {
        return \App\Models\SiteData::first();
    }
}

if (!function_exists ('social')) {
    function social()
    {
        return \App\Models\Social::first();
    }
}

if (!function_exists ('contact')) {
    function contact()
    {
        return \App\Models\Contact::first();
    }
}

bestmomo left a reply on Helper Function

Remove these lines :

namespace App\Http;
class helpers
{

It's not a class just a php file with functions

bestmomo left a reply on Helper Function

Dont forget namespaces :

<?php

if (!function_exists ('sections')) {
    function sections()
    {
        return \App\Models\Section::all();
    }
}

if (!function_exists ('site_data')) {
    function site_data()
    {
        return \App\Models\SiteData::first();
    }
}

if (!function_exists ('social')) {
    function social()
    {
        return \App\Models\Social::first();
    }
}

if (!function_exists ('contact')) {
    function contact()
    {
        return \App\Models\Contact::first();
    }
}

bestmomo left a reply on Helper Function

Why not simple like that :

if (!function_exists ('sections')) {
    function sections()
    {
        return \App\Models\Section::all();
    }
}
...

bestmomo left a reply on Helper Function

I have updated my answer.

bestmomo left a reply on How To Access Public Path Image

$output = '
        <td><img height="50" src="' . url("/imageslogo-1.png") . '" alt="Image"/></td>
  '

bestmomo left a reply on Helper Function

The simple way is to create an app/helper.php file for all your helper functions and load it with composer :

"autoload": {
    "classmap": [
        "database/seeds",
        "database/factories"
    ],
    "files": [
        "app/helpers.php"
    ],
    "psr-4": {
        "App\": "app/"
    }
},

In your helper file you set your helper methods, for example :

<?php

if (!function_exists ('currentRoute')) {
    function currentRoute(...$routes)
    {
        foreach ($routes as $route) {
            if (request ()->url () == $route) {
                return ' active';
            }
        }
    }
}

bestmomo left a reply on Helper Function

Why do you extend Controller to make an helper ?

bestmomo left a reply on How To Access Public Path Image

I dont understand how you manage your code. Why dont you use Blade for this ?

08 Sep
5 months ago

bestmomo left a reply on Laravel 5.7 Email Confirmation

Now I've got it ;)

bestmomo left a reply on Laravel 5.7 Email Confirmation

@staudenmeir

Right, I made copy and paste to have link and got &amp; , thanks ;)

07 Sep
5 months ago

bestmomo left a reply on Laravel 5.7 Email Confirmation

Yes I did all that is said in doc : implements MustVerifyEmail in User and 'verify' => true in routes.