florianhusquinet

Project Developer at TrustUp

Experience

15,220

4 Best Reply Awards

  • Member Since 2 Years Ago
  • 123 Lessons Completed
  • 0 Favorites

14th August, 2018

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

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.

13th August, 2018

florianhusquinet left a reply on How To Display And Update In Same Blade • 1 month ago

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 • 1 month ago

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 • 1 month ago

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 • 1 month ago

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 • 1 month ago

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 • 1 month ago

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? • 1 month ago

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 • 1 month ago

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

16th May, 2018

florianhusquinet left a reply on Laravel Best PDF Package • 4 months ago

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.

11th May, 2018

florianhusquinet left a reply on React, Csrf • 4 months ago

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 • 4 months ago

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.

1st May, 2018

florianhusquinet left a reply on XSS On Laracasts • 4 months ago

I have looked at the profile of m-rk

5th December, 2017

florianhusquinet left a reply on UserRepository (interface) & EloquentUser • 9 months ago

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

20th November, 2017

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

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?

14th November, 2017

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

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 • 10 months ago

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?

17th October, 2017

florianhusquinet left a reply on SortBy And Accented Words • 11 months ago

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 • 11 months ago

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

16th October, 2017

florianhusquinet left a reply on How To Query Pivot Table Where Clause? • 11 months ago

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 • 11 months ago

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 • 11 months ago

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 • 11 months ago

@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] • 11 months ago

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

15th October, 2017

florianhusquinet left a reply on Posting Data To Laravel App From VueJS • 11 months ago

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 • 11 months ago

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 • 11 months ago

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 • 11 months ago

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/

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.