Vilfago

Experience

50,500

64 Best Reply Awards

  • Member Since 6 Months Ago
  • 41 Lessons Completed
  • 2 Favorites

22nd September, 2018

Vilfago left a reply on Order By With Relationship • 1 day ago


$followers = $user->load(['followers' =>function($query) {
    $query->orderBy('date', 'desc')->limit(12); }]);

21st September, 2018

Vilfago left a reply on HasMany To All • 1 day ago

\App\Models\Company::all() is correct.

But I don't understand why you do that in the model, it's a controller work. If user is admin, all companies, else only the relation

Vilfago left a reply on Searchable Arrays In Database • 1 day ago

If a topic could be assigned to many website, and a website could have many topics, it will be a many to many.

If you don't know, it's safer to build a many to many, as it allow you to make a one to many, or a one to one if needed (but less efficient than an usual one to one relation)

Vilfago left a reply on Searchable Arrays In Database • 2 days ago

You can set a many-to-many relationship between your user and segments

https://laravel.com/docs/5.7/eloquent-relationships#many-to-many

20th September, 2018

Vilfago left a reply on Eloquent Find Vs Where/get • 2 days ago

find() will always retrieve data per primary key (define in the model). The key on your array is not used, and is not intended to be a column name.

So yes you get data, but maybe not the data you wanted.

Vilfago left a reply on Single Model With BelongsToMany : How To Query? • 2 days ago

As always, it depends what you need the most. If it's a one time query, I'll go with your solution.

If he rarely update the owner's account, I think my solution is better has he can get what he wants with only one relation.

Vilfago left a reply on Single Model With BelongsToMany : How To Query? • 2 days ago

oh yes, sorry

$user->allAccounts()->updateExistingPivot($accountId, ['is_owner' => 1]);

Vilfago left a reply on Single Model With BelongsToMany : How To Query? • 2 days ago

Why complicated ?

class User extends Model
{
    /**
     * The roles that belong to the user.
     */
    public function allAccounts()
    {
        return $this->belongsToMany('App\Account')->withPivot('is_owner');
    }

    public function ownAccounts()
    {
        return $this->belongsToMany('App\Account')->withPivot('is_owner')->wherePivot('is_owner', 1);
    }

    public function sharedAccounts()
    {
        return $this->belongsToMany('App\Account')->withPivot('is_owner')->wherePivot('is_owner', 0);
    }
}

Vilfago left a reply on Single Model With BelongsToMany : How To Query? • 2 days ago

Yes, from my side it's easier this way

Vilfago left a reply on Single Model With BelongsToMany : How To Query? • 2 days ago

You can do it in the pivot table account_user with three column :

  • account_id
  • user_id
  • is_owner (bool)

If you want only the account for which the user is the owner, you add a where clause on the "is_owner" column, and otherwise you can just take $user->accounts();

19th September, 2018

Vilfago left a reply on Relationship Issues • 3 days ago

What is a user if it's not a doctor neither a patient ?

Vilfago left a reply on Changing The Default "subject" Field For The Verification Email In Laravel 5.7 • 3 days ago

I guess this is not in resources/views/auth/verify.blade.php or in resources/lang folder ?

Vilfago left a reply on Relationship Issues • 3 days ago

$doctors = Auth::user()->load('practices.doctors')->sortBy('name', 'asc')->paginate(10);

Vilfago left a reply on Validation: One Selection Invalidates Another. • 3 days ago

I think Laravel have nothing to test if something does not exist, as if you want it empty, even if there is something, you won't use it... so why worry ?

But you can create your own validation rule if needed : https://laravel.com/docs/5.7/validation#custom-validation-rules

Vilfago left a reply on Return Resource::collection With Foreach • 3 days ago

$properties = Property::join('city', 'cities.id', '=', 'properties.city_id')
->join('type', 'type.id', '=', 'properties.type_id')
->join('office', 'office.id', '=', 'properties.office_id')
->with(['property_images' => function ($query) {
    $query->select('urlnormalizedfile','property_id') }]));where('office_id', 1)->where('online', '1')
->get();

Vilfago left a reply on Group By And Paginate • 4 days ago

What do you want to do with your selected fields when they are merged ?

It take you the last ID ? Sum all id ?

I think the issue come from that.

$headlines = ProgramHeadline::count('id')->groupBy('month')->paginate(6);

But you'll probably have the same issue with another column.

Vilfago left a reply on Validation: One Selection Invalidates Another. • 4 days ago

so field B is required if field A is true.

"field_B" => "required_if:field_A,==,true"

Vilfago left a reply on Return Resource::collection With Foreach • 4 days ago

What do you try to achieved ?

Could we see the whole PropertyResource.php ?

When and how are you calling toArray() method ?

Vilfago left a reply on How To Write Correct URL In Ajax • 4 days ago

You cannot delete your double, just let the other one fall down.

As @lostdreamer_nl said, just rename your file from anything.js to anything.blade.php

If it's not a php file, you cannot use a php/laravel function

Vilfago left a reply on Validation: One Selection Invalidates Another. • 4 days ago

Maybe this could help : https://laravel.com/docs/5.7/validation#rule-required-if

Or the ones below

Vilfago left a reply on Join Table Using Eloquent • 4 days ago

You can use ->join() on a Eloquent model, all Query builder method could be used with Eloquent.

You can also use with() to retrieve data in another table.

Vilfago left a reply on How To Write Correct URL In Ajax • 4 days ago

Why you double slash ? //

You can also use route(....) or action(...) that I find easier to use. https://laravel.com/docs/5.7/urls

Vilfago left a reply on When To Break REST. • 4 days ago

An interesting watch on how everything is (could be) CRUD : https://www.youtube.com/watch?v=MF0jFKvS4SI

Vilfago left a reply on Sending A Lot Of Mail Via Mail::send Method • 4 days ago

Which version of Laravel do you use ? Seems that Mail::send changed to Mail::to in last versions.

And are you sure of the content of $user_email inside your function ?

Vilfago left a reply on One To Many Definition And Foreign Key • 4 days ago

To have a counter argument, I heard to avoid foreign key as most as possible, to improve the speed of the database as it could take a lot more resources on insert/update/delete.

The integrity constraint should be ensure with some control in your code, that you obviously will do before inserting/updating some data. If the error come from the database, it's "too late".

18th September, 2018

Vilfago left a reply on Relationship Issues • 4 days ago

User and patient are the same ?

I think we have to view how you set the relations in the models.

Vilfago left a reply on I Wanna Get All Articles With Votes • 4 days ago

It depends how you stored it, but you can try

$articles = 
Article::with('user', 'categorie', 'comments', 'votes')
    ->has('votes', '>=', 5)
    ->where('created_at', '<=', Carbon::now()->subHour(1))
    ->paginate(20);

https://laravel.com/docs/5.5/eloquent-relationships#querying-relationship-existence

17th September, 2018

Vilfago left a reply on Need Advice About Model Relations • 6 days ago

Your first thought was the good one for my perspective. It allow you to do all you need and stay simple.

Vilfago left a reply on What Is The Problem On My Php Code!! • 6 days ago

Put the code between ```

And don't choose best answer before it's resolved

Vilfago left a reply on Share Value Between Function In Same Controller • 6 days ago

Are you sure that searchProduct() stand alone return something ?

16th September, 2018

Vilfago left a reply on Students Position From Average • 6 days ago

$array_results = [3101625668 => 98.0, 3101635921 => 98.0, 3913126364 => 35.77, 3913058204 => 25.33, 3101372540 => 33.47, 3913752741 => 40.0, 3913120054 => 20.4, 3913998755 => 26.67, 3913861492 => 25.2, 3913881854 => 19.8,];
        
        $results = collect($array_results);
        dump($results);
        $results_sorted = $results->sort()->reverse();
        dump($results_sorted);
        $current_rank = 1;
        $number_in_position = 0;
        $current_score = 100;

        foreach($results_sorted as $pin => $result)
        {
                if($result < $current_score){
                        $current_score = $result;
                        $current_rank += $number_in_position;
                        $number_in_position = 1;
                        $output[$pin] = [$current_rank, $result];
                }else{ //same score as the previous
                        $number_in_position++;
                        $output[$pin] = [$current_rank, $result];
                }
        }

        dd($output);

15th September, 2018

Vilfago left a reply on Generate Html Table • 1 week ago

If the issue was too many requests due to foreach, try to eager load your data : https://laravel.com/docs/5.7/eloquent-relationships#eager-loading

Vilfago left a reply on Generate Html Table • 1 week ago

What did you try?

Vilfago left a reply on Students Position From Average • 1 week ago

Did you try my code? I'm tired too

14th September, 2018

Vilfago left a reply on Students Position From Average • 1 week ago

Yes... he told you he didn't do this part...

Vilfago left a reply on How To Hide .env File • 1 week ago

@jirdw don't worry, just an old thread coming back... 2 years old @Snapey I use the spam button, maybe it do the work ?

Vilfago left a reply on Students Position From Average • 1 week ago

$results = collect([$array_results]);

$results_sorted = $results->sort()->reverse();

$current_rank = 1;
$number_in_position = 0;
$current_score = 100;

foreach($results_sorted as $pin => $result)
{
    if($result < $current_score){
        $current_score = $result;
        $current_rank += $number_in_position
        $number_in_position = 1;
        $output[$pin] = [$current_rank, $result];
        ++;
    }else{ //same score as the previous
        $number_in_position++;
        $output[$pin] = [$current_rank, $result];
    }
}

dd($output);

I didn't test it, I let you some job (test, debug, optimize)

Vilfago left a reply on How Do I Get All Select Elements That Do Not Have An Option Selected Using JQuery? • 1 week ago

Try, it should work...

And if not, log the value in console to see what it is.

Vilfago left a reply on Eloquent • 1 week ago

Do you have data which match with all your where clauses ?

Vilfago left a reply on How Not To Repeat Your Code In All Controller Routes? • 1 week ago

You create a BaseController extending Controller with some protected functions, and all your controllers extends this base controllers.

And you call the function when needed.

Or if you need it outside Controller, use Traits.

Vilfago left a reply on Students Position From Average • 1 week ago

Could you provide me the output you want ? An array with a sub-array containing pin and value ? Key as rank, or value for rank?

Vilfago left a reply on Students Position From Average • 1 week ago

Sort your data by values : https://laravel.com/docs/5.7/collections#method-sort And then you can loop trough it, and implement a counter for the ranking.

Vilfago left a reply on Lumen Intro • 1 week ago

It depends on which module you will need.

If nothing else than standard Lumen, go with it. If you have to add tons of module coming from Laravel, it will be slower than Laravel.

Vilfago left a reply on How Do I Get All Select Elements That Do Not Have An Option Selected Using JQuery? • 1 week ago

Explain a bit more if you want some help, don't just up your thread

Vilfago left a reply on How Not To Repeat Your Code In All Controller Routes? • 1 week ago

What is the purpose of these chats and message ? If you want to show them on the view, you can use a view composer.

Add your method in the view composer, amd just call it when needed.

13th September, 2018

Vilfago left a reply on I Want To Read A Exal Data In Blade.php But I Have Error In This Code • 1 week ago

http://php.net/manual/en/control-structures.foreach.php

foreach($smpl as $file)
{
        $fname = $file->filename();
        $opendoc = file_get_contents(public_path('uploads' . $fname));
}

return View::make('view' , compact('title', 'smpl'));

I didn't see that you didn't open it neither.

Vilfago left a reply on Call To Undefined Function App\Http\Controllers\[Name] In File • 1 week ago

In Engagement::where('client_id', client()->id)->get();, client()->id has no meaning... you have to pass the id somewhere ?

For example in your route : Route::get('/client-engagements/{id}', '[email protected]');

and then, your controller :

public function clientindex($client_id)
    {
        return Engagement::where('client_id', $client_id)->get();
    }
Edit Your Profile
Update

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