florianhusquinet

florianhusquinet

Project Developer at TrustUp

Liege

Member Since 2 Years Ago

Experience Points 15,320
Experience
Level
Lessons Completed 124
Lessons
Completed
Best Reply Awards 4
Best Answer
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.

14 Aug
3 months ago

florianhusquinet left a reply on How To Change School_id To A Int For Save In Database?

You are trying to access $request->school_id but you are not passing that parameter in your Ajax request:

$.post("{{ route('schools-list.store') }}", {province_id:province_id, city_id:city_id, center_id:center_id}, function (data_school) {
            var school_id = {school_id: data_school.id} ;
            console.log(school_id);
        });

You should include the school_id along with the province_id and your other parameters if you wish to access it.

13 Aug
3 months ago

florianhusquinet left a reply on How To Display And Update In Same Blade

An exemple for what exactly?

I would honestly just do a page to edit a single profile, here's the logic: The route would be /admin/profiles/{id}/edit Retrieve the profile with the id in the controller and display the view Display the inputs required in the view using $profile->id, $profile->user->id and $profile->organization->id (id being just an example here).

You will have a much easier time dealing with the update next since you are dealing with a single profile. You retrieve it, set the new values then save it and you are done.

florianhusquinet left a reply on Dynamic NavBar

You can use redis or memcached if you really need to have a "professional solution", but honestly throwing in a single query on each page load isn't that big of a deal unless that query is a mess or the rest of your site is.

Just use

Cache::remember($duration, function () {
    return Nav::all(); // Your query/logic here
});

and you'll be fine.

florianhusquinet left a reply on How To Display And Update In Same Blade

The $profiles variable is an eloquent collection, you cannot access a relationship/organization of the underlying models.

You should either loop through each profile/user then access the property or display a page to edit a single user at a time (which is most likely a way better idea).

florianhusquinet left a reply on Dynamic NavBar

Do you want to store it in session to have prevent querying it on each page load? If so you should look at caching instead.

florianhusquinet left a reply on Use Named Route And Asset In Controller

You are using blade tags inside your controller which is not valid. You should use the regular php syntax instead.

<img src=". asset("storage/images/avatar5.png") . ">
<a href=".route('admin.viewUser',['id'=>$user->id])." class="btn d-inline"></a>

florianhusquinet left a reply on Admin ,Users ---> Separate Table VS Single Table

If you decide to build an extra table for the admins you then have to extend the default auth system which is a lot of extra work considering you could simply have a role and do $user->hasRole('admin') when needed.

Another option if you do not want to use roles nor a flag and need extra columns for your admins is to use a one to one relationship. Your admins table can have the user_id as well as the columns you need without messing with Laravel's auth system.

florianhusquinet left a reply on How To Get This Job Done?

Not really no. Just use the default auth from Laravel, you can use gates and policies in case you want to prevent/allow your users from doing certain tasks.

florianhusquinet left a reply on Dynamic NavBar

Laravel 5.4 supports View Composers out of the box, which is the case since at least version 4.2: https://laravel.com/docs/5.4/views#view-composers

16 May
5 months ago

florianhusquinet left a reply on Laravel Best PDF Package

I believe laravel-dompdf is a great package which should do the job just fine. Bootstrap is a huge framework which isn't needed to compile a simple pdf file using a blade view in my opinion.

If you can, just create a custom CSS sheet for that PDF, writing it inline reduces workload as well.

YMMV but I've had great success using laravel-dompdf, maybe post a bit more details on what kind of PDF you are trying to generate.

11 May
6 months ago

florianhusquinet left a reply on React, Csrf

The docs has a small section on that: https://laravel.com/docs/5.6/csrf#csrf-x-csrf-token

Basically setting the CSRF Token in a meta tag inside your app.blade.php file (or whatever file is your main template each view is extending) and getting the meta value to set it in your XHR method of choice (axios, jQuery...).

florianhusquinet left a reply on Get Accurate Query Execution Time

You can use the barryvdh/laravel-debugbar package to see every query made on every page more easily. Making a query directly into your database is often quite a bit faster than doing it through an ORM as @36864 said.

01 May
6 months ago

florianhusquinet left a reply on XSS On Laracasts

I have looked at the profile of m-rk

05 Dec
11 months ago

florianhusquinet left a reply on UserRepository (interface) & EloquentUser

You are missing the use App\User statement in your EloquentUser class.

20 Nov
11 months ago

florianhusquinet left a reply on About View Composers - Cannot Get It To Work - Laravel 5.5

Your class should be called NavbarBackendComposer, it is currently called NavbarBackend which is surprisingly not throwing an exception...

If you execute go on a page using the layouts.backend view and setup a dd($results) in the composer method of the NavbarBackendComposer, can you see the result?

14 Nov
1 year ago

florianhusquinet left a reply on What Is The Purpose Of Using & Registering Service Providers?

A service provider is a class that is used throughout your app without the need to register them on the specific file you need.

For example the RouteServiceProvider is a class laying out the basic configuration for the routing of your application. You can customize it to your need. Another example would be a ViewComposerServiceProvider used to always send a variable to one or multiple view(s). This is useful when you have a partials used on multiple pages and you do not want to worry about querying your database on every controller.

florianhusquinet left a reply on Cant Change Default Authentication From User Model To Admin Model In Auth.php Config

I wouldn't recommend renaming the users table just because "admin" sounds better. Laravel uses the logic that authentification should only be done on a single table, and roles, guards, and permissions should define what the user has access to (for example an admin area).

Though changing it should be as trivial as changing the line you quoted the config/auth.php file, you should also make sure the RegisterController is using the correct validation and model (if need be).

Can you tell us more about when this error happen?

17 Oct
1 year ago

florianhusquinet left a reply on SortBy And Accented Words

No problem, it can be quite confusing at first, especially when the methods' name are so similar.

florianhusquinet left a reply on SortBy And Accented Words

I have to agree with @andonovn on this one, it looks like you are trying to execute orderByRaw on a collection after the query has been executed.

The sortBy method should be used on a collection (a collection being wrapper of an array of datas) while the orderBy and orderByRaw methods are meant to be used on the query builder.

Here is an example using both methods:

$users = User::orderBy('first_name')->get(); // User being a model, this is a query
/*
    [
        [
            'first_name' => 'Benton',
            'last_name' => 'Hanks'
        ],
        [
            'first_name' => 'Johanna',
            'last_name' => 'Smith'
        ],
        [
            'first_name' => 'Laurence',
            'last_name' => 'Colt'
        ]
    ];
*/


$sorted = $users->sortBy('last_name');
/*
    [
        [
            'first_name' => 'Laurence',
            'last_name' => 'Colt'
        ],
        [
            'first_name' => 'Benton',
            'last_name' => 'Hanks'
        ],
        [
            'first_name' => 'Johanna',
            'last_name' => 'Smith'
        ]
    ];
*/

You can learn more about collections, query builder and their respectives methods here (and there is a lot...): https://laravel.com/docs/5.5/collections https://laravel.com/docs/5.5/queries

16 Oct
1 year ago

florianhusquinet left a reply on How To Query Pivot Table Where Clause?

First of your query won't work because you are using findOrFail() which stops the query at that point.

Try this example, where 'relationship' is the name of the Many-To-Many relationship related to your Department model.

$departments_past = Department::where('batch_centre_id','=', $id)
  ->whereHas('relationship', function($q) {
    $q->wherePivot('term_end_date', '<', '2017-10-10');
  });

florianhusquinet left a reply on SortBy And Accented Words

You can use the orderByRaw method to do order your query just like a normal query if @andonovn's method does not work and MySQL doesn't return the expected results by itself (it might)

Something like this:

$users = Users::orderByRaw('last_name COLLATE utf8_french_ci');

florianhusquinet left a reply on Multiple Form Requests

I understand your point of view, though mixing everything in one single request to handle it as you wish might be a bit simpler.

If you absolutely prefer to separate both logic then I would do a nested api call, something like this (using VueJS):

methods: {
    createUser()
    {
        axios.post('/api/users', your_user_data)
                    .then( response => {
                            this.createClient(response.data.user);
                    }, error => {
                            // Handle errors like validation
                    });
    },
    createClient(user)
    {
        axios.post('/api/users/' + user.id +  '/clients', your_client_data)
                    .then( response => {
                            // Show success
                    }, error => {
                            // Handle errors like validation
                    });
    }
}

Please note that this small example does not take into consideration your validation.

florianhusquinet left a reply on SortBy And Accented Words

@andonovn It looks like a problem from the sortBy method used on a collection and not the orderBy method used on a query.

@Corban

I don't think sortBy support UTF-8 characters by default, which is the issue here. I've found this solution on stackoverflow:

setlocale(LC_COLLATE, 'fr_FR.utf8'); // No need to set this if you're doing it elsewhere

$collection->sortBy("name", SORT_LOCALE_STRING); // Signals to arsort() to take locale into consideration

https://stackoverflow.com/questions/39374842/laravel-5-3-collection-sort-utf8-strings

Another solution might be to change your query if that's a possibility. MySQL handles sorting pretty well and it will take off a bit of the complexity from your controller/view.

florianhusquinet left a reply on How To Fix Artisan? Php Artisan Optimize Throws A [ReflectionException]

You use the -v flag on your command which is used to increase the verbosity of the output making it a bit more understandable. You can learn more about it here: http://www.gnu.org/software/tar/manual/html_node/verbose-tutorial.html

15 Oct
1 year ago

florianhusquinet left a reply on Posting Data To Laravel App From VueJS

Here is a basic example on what your axios request could look like in your submitForm method:

axios.post('/your-post-url/', this. registros)
                    .then( response => {
                        // Handle success response
                    }, error => {
                        // Handle error response
                    });

Your controller looks correct though you should always have the "network / xhr" tab of your Chrome console open when testing XHR requests to see what data is passed and how your server reacts to it. Do not forget to validate it as well.

florianhusquinet left a reply on How To Fix Undefined Variable: Collaborators

Indeed you need to pass the variable $collaborators to your view like this:

Route::get('/project/{project}/collaborators', function(){ 
       return view('collaborators.form', ['collaborators' => $collaborators']); 
    })->name('collaborators.form');

Obviously you would need to query your database (or else depending on your logic and project) before to define your variable, which could look like this:

Route::get('/project/{project}/collaborators', function(){ 
    $collaborators = App\Models\Collaborator::all();
       return view('collaborators.form', ['collaborators' => $collaborators']); 
    })->name('collaborators.form');

florianhusquinet left a reply on Posting Data To Laravel App From VueJS

What you need to do is a post request to your backend using Axios (for example). Here is a great tutorial on Laracasts which should explain everything you need:

https://laracasts.com/series/learn-vue-2-step-by-step/episodes/18

florianhusquinet left a reply on Adding Birthday To Register Form

You could use a simple datetime field and insert either a formatted value (ex 1986-02-19 12:00:00) or a valid Carbon instance. I would recommend using a good date picker field to improve the user experience, and validate it in the backend to make sure it is filled correctly.

Check out these docs for code examples and details on how to do it: https://laravel.com/docs/5.5/migrations#creating-columns https://laravel.com/docs/5.5/validation#rule-date http://carbon.nesbot.com/docs/