Vilfago

Experience

49,800

63 Best Reply Awards

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

19th September, 2018

Vilfago left a reply on Relationship Issues • 7 hours 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 • 12 hours 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 • 13 hours ago

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

Vilfago left a reply on Validation: One Selection Invalidates Another. • 13 hours 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 • 14 hours 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 • 17 hours 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. • 17 hours 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 • 17 hours 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 • 17 hours 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. • 17 hours 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 • 18 hours 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 • 18 hours 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. • 18 hours 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 • 20 hours 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 • 20 hours 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 • 1 day 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 • 1 day 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 • 2 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!! • 2 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 • 2 days ago

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

16th September, 2018

Vilfago left a reply on Students Position From Average • 3 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 • 4 days 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 • 4 days ago

What did you try?

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

Did you try my code? I'm tired too

14th September, 2018

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

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

Vilfago left a reply on How To Hide .env File • 5 days 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 • 5 days 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? • 5 days ago

Try, it should work...

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

Vilfago left a reply on Eloquent • 5 days 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? • 5 days 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 • 5 days 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 • 5 days 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 • 5 days 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? • 5 days 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? • 5 days 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 • 6 days 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 • 6 days 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();
    }

Vilfago left a reply on Votes For Article Do Not Count Properly • 6 days ago

Like sync() and detach(), no ?

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

The error come on the line $opendoc = ... ?

Vilfago left a reply on Pass Variables From Controller To View • 6 days ago

So you can close the thread in selecting the "best answer", and don't hesitate to come back if needed.

Vilfago left a reply on Votes For Article Do Not Count Properly • 6 days ago

You can use toggle method, could be easier.

public function store(Article $article, Request $request)
{
    auth()->user()->votes->toggle([$article]);

        return response()->json(['success' => true, 'count' => $article->votes->count()]);
}

and nothing in your model except the relation between user and vote.

Vilfago left a reply on Pass Variables From Controller To View • 6 days ago

Ok, I must read what I gave you more carefully, still a typo.

return view('about')->with('crypto ', $cryptocurrency); should be return view('about')->with('crypto', $cryptocurrency);

Vilfago left a reply on Pass Variables From Controller To View • 6 days ago

you're right, it was a typo. As it's a variable, the "$" is missing.

Replace by : $bitcoinRate = $cryptocurrency->BTC;

Vilfago left a reply on Pass Variables From Controller To View • 6 days ago

Your code :

public function about() {
    $api_url = 'https://min-api.cryptocompare.com/data/pricemulti?fsyms=BTC&tsyms=EUR,USD';
    $cryptocurrency = json_decode(file_get_contents($api_url));
    $crypto = array();
    foreach ($cryptocurrency as $key => $value) {
        $value = array();
        $value['priceUSD'] = (float) $cryptocurrency->$key->EUR;
        $value['priceEUR'] = (float) $cryptocurrency->$key->USD;
        array_push($crypto, $value);
    }
    
    return view('about');
}

Should/could be (but I don't have data to test, so not sure its works) :

//Controller
public function about() {
    $api_url = 'https://min-api.cryptocompare.com/data/pricemulti?fsyms=BTC&tsyms=EUR,USD';
    $cryptocurrency = json_decode(file_get_contents($api_url));
    
    return view('about')->with('crypto ', $cryptocurrency);
}

//View
@foreach ($crypto as $currency)
    <p>Un bitcoin vaut : {{ currency->EUR }} euros</p>
    <p>Un bitcoin vaut : {{ currency->USD }} dollars</p>
@endforeach

or

//Controller
public function about() {
    $api_url = 'https://min-api.cryptocompare.com/data/pricemulti?fsyms=BTC&tsyms=EUR,USD';
    $cryptocurrency = json_decode(file_get_contents($api_url));
    $bitcoinRate = cryptocurrency->BTC;
    
    return view('about')->with('bitcoinRate', $bitcoinRate );
}

//View
<p>Un bitcoin vaut : {{ bitcoinRate->EUR }} euros</p>
<p>Un bitcoin vaut : {{ bitcoinRate->USD }} dollars</p>

Vilfago left a reply on Laravel API • 6 days ago

Vilfago left a reply on Search Db Using Scope And Relationships • 6 days ago

Shouldn't you use orWhereHas instead of whereHas?

Vilfago left a reply on Laravel API • 6 days ago

You return a json, so you can call it with Ajax, for example

Edit Your Profile
Update

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