Vilfago

Vilfago

Member Since 1 Year Ago

Neuch√Ętel

Experience Points 93,780
Experience Level 19

1,220 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 104
Lessons
Completed
Best Reply Awards 120
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.

17 May
2 days ago

Vilfago left a reply on How To Create Two Columns With @foreach?

Could you dump($services); so we can see what's in it.

But I guess each item doesn't contain an array...

09 May
1 week ago

Vilfago left a reply on Method Illuminate\Support\Collection::paginate Does Not Exist

You can simulate the paginate with take and skip

03 May
2 weeks ago

Vilfago left a reply on Eloquent Optimizations

If it's for statistic, don't get the data, but count it directly in the database.

Count the total, count the canceled, etc. It will be faster.

08 Mar
2 months ago

Vilfago left a reply on Nested Relationships Query

It's sometimes easier to start with the User if it's what you need,

$user = User::with('apps.fees.purchases.payments.refunds')->findOrFail(1);
27 Feb
2 months ago

Vilfago left a reply on First Time Model Binding

Apply this : https://laravel.com/docs/5.7/eloquent-relationships#one-to-many (set relationships).

And then : $types = Type::with('extensions')->get();

14 Feb
3 months ago

Vilfago left a reply on Optional Router Params

You can try something like : ``` Route::get('cars/{parameters?}', 'Cars\[email protected]') ->where('parameters', '(.*)');


It will get all url which are "api/cars/anything-you/can-write/with_your*keyboard"

And then, you should add some constraint in your controller (explode the url, and get the delimiter and filter which was provided.

But why not use : api/cars?price=10000-20000&year=2013-2018&color=blue

Vilfago left a reply on Optional Router Params

It's like a php function. If 4 parameters are optional, but you want to specify the third one, you have to specifiy the one and two before.

In your case laravel check that "price" = year as it's come first... and is it's not the case you got a 404.

You have to try with something like cars/year/any/price/10000-20000

Vilfago left a reply on How Can I Save Duplicate Record In Laravel ?

$opening = Opening::find($id);
$replicate = clone $opening;
$replicate->save();

Maybe, you will have to reset the primary key

$opening = Opening::find($id);
$replicate = clone $opening;
$replicate->id = NULL;
$replicate->save();

Vilfago left a reply on Is This The Right Way Of Editing A Form?

You can also upgrade to 5.7 :)

Vilfago left a reply on Secure The Ids That Are Send To Views

I don't know what you want to do with "encrypt", but you can use a slug.

https://laravel.com/docs/5.7/routing#route-model-binding

Go to Customizing The Key Name

Vilfago left a reply on Problem With Latin Words

If it's MySql, you need utf8_mb4 to have a true UTF-8.

https://dev.mysql.com/doc/refman/8.0/en/charset-unicode-utf8mb4.html

13 Feb
3 months ago

Vilfago left a reply on Passing Second Parameter To Controller Having 404

This could be a solution ? (optional parameter)

Route::get('asset/{theme_id}/{key}/{page?}', ['as' => 'asset.view', 'uses' => '[email protected]']);

Vilfago left a reply on Pluck Multidimensional Array

You cannot get what you want with eloquent, as it will need the foreign_key and primary_id to match the data fetched.

So you need to retrieve more column that you want.

Why don't you want to use your join query, if it works ?

Vilfago left a reply on Two Different Databases On Same Query

Yes, you can specify the connection on each model, so you can create several model, and use eloquent relations to retrieve data from multiple databases.

Vilfago left a reply on HomeController::index (Long Loading Time) Collection Issue

Do you really have to query your database again ? the visual property isn't alreday loaded ?

It may be more efficient to check if you have the visual in local (/uploads/visuals/), and if not, get it from s3. Currently you ask for every visual s3, and your user will have to request it again for display.

I don't really know how s3 handle these requests, but I'm quite sure it's faster to check if the local file exist instead of a file on s3.

What is the result of the console/debugbar for loading time ?

12 Feb
3 months ago

Vilfago left a reply on A Simple Question About Posting A Form

It could be better to respect laravel convention, and keep model in singular form. So Post instead of Posts.

btw, if you got your answer, you can close the thread choosing the best answer.

Vilfago left a reply on A Simple Question About Posting A Form

If the objective of your form is creating new posts, yes it's the right route for that.

Vilfago left a reply on Create Pivot Table For One To Many Relationship

You can do on one table using polymorphic relation.

For allowing only one national card, you will maybe have to add some policy : https://laravel.com/docs/5.7/authorization

Vilfago left a reply on Create Pivot Table For One To Many Relationship

I guess you have 3 tables

national_cards // id | user_id | image bank_cards // id | user_id | image salafi_cards // id | user_id | image

Vilfago left a reply on A Simple Question About Posting A Form

<form action="{{ route('insert') }}" method="POST"> will send the data of the form to the route insert with a post method.

You can get it in the controller using the request helper

public function store(Request $request)
{
    dd($request->all());
}

By the way Route::resource('posts', 'PostController'); will create several routes (see https://laravel.com/docs/5.7/controllers#resource-controllers ), so route('insert') is the same than route('posts.store'). Both are related to "[email protected]".

So you can delete your Route::post(...`` and use`

Vilfago left a reply on Proper Way To Sum Two Variables In A Cyclic Manner?

Yes that's correct, but you should assign a number, as you will make an addition.

$foo = '0'; //this is a string
$foo = "0"; //this is a string
$foo = 0; //this is a integer (number)
$foo = 0.00 //this is a float (number)
$foo = "0.00"; //this is a string

Vilfago left a reply on How To Populate Timezone Selectbox

So it is solved ?

If yes, close this thread by selecting a best answer (and all your other solved threads).

Vilfago left a reply on Proper Way To Sum Two Variables In A Cyclic Manner?

Why do you set the value of $val_sum with a string and not 0 ?

            //sum the vals in the query
            $val_sum = 0;
            foreach ($nrcan_consump_records_options as $option) {
                $val_sum = $val_sum + $option->val;
            };

or

            //sum the vals in the query
            $val_sum = 0;
            foreach ($nrcan_consump_records_options as $option) {
                $val_sum += $option->val;
            };

Which line is incorrect for PHPStorm ?

11 Feb
3 months ago

Vilfago left a reply on How To Convert Big Name To Short

To go deeper, you can use this : http://php.net/manual/en/language.types.string.php#language.types.string.substr

And you can dynamicly check the number of names

$name = 'Ram Kumar Vermar';

if(strlen($name) > 16) {
    $nameArr = explode(' ', $name);
    $numberOfNames = count($nameArr);

    for($i = 0; $i < $numberOfNames ; $i++){
        if($i == $numberOfNames - 1){
            $name .= $nameArr[$i];
        }else{
            $name = $nameArr[$i][0];
        }
    }
}

return $name;

The question is what you want to do if the name is "Ram Kumar Meenakshisundaram" (more than 16 characters in the last name).

Vilfago left a reply on PDOException: Could Not Find Driver (for SQLite)

config/database.php

'default' => env('DB_CONNECTION', 'sqlite'),
'connections' => [

        'sqlite' => [
            'driver' => 'sqlite',
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
        ],
]

You can set it in the .env file at your root folder, under the name "DB_CONNECTION" and "DB_DATABASE". The second argument is the default value if the first one is not known.

Vilfago left a reply on Need Advice For Developing An ERP

Not from a technical point of view, but for selling... It could be a good argument to say that each customer have is own database, and that information will never cross one of a competitor.

07 Feb
3 months ago

Vilfago left a reply on Route Parameter Delivers Locale Instead Of ID

I think your route is inside a route group which already contain a parameter (for language by example).

Vilfago left a reply on How To Custom Button Text On Resources

Yes

<button type="button" class="btn btn-primary">Your custom text</button>

But I wonder if it was really your question :) Could you be more specific, with some code you already have ?

06 Feb
3 months ago

Vilfago left a reply on How To Get Multiple Images

put your code between two ```

It will be readable like that :)

04 Feb
3 months ago

Vilfago left a reply on JSON Update Query Runs Nothing Changes In Database?

Yes...

Could you clean up your json, having something like {"1": "[email protected]_1.jpeg", "2": "[email protected]_2.jpg", "3": "[email protected]_3.jpg", "4": "[email protected]_4.jpg", "5": "[email protected]_5.jpeg"}?

$data_json = '{"1": "[email protected]_1.jpeg", "2": "[email protected]_2.jpg", "3": "[email protected]_3.jpg", "4": "[email protected]_4.jpg", "5": "[email protected]_5.jpeg"}';
$data = json_decode($data_json, TRUE);

unset($data[1]);
$data_to_save = json_encode($data);

$postImage = PostImage::where('post_id', $post->id)->update(["image" => $data_to_save]);

It will be easier.

Vilfago left a reply on Getting The Total Quantity To Be Displayed

And what "not displaying correctly" mean ?

Not the right value ? The format is not what you expect (in this case : what did you expect) ? Something else ?

Vilfago left a reply on JSON Update Query Runs Nothing Changes In Database?

Maybe there is a cleaner solution, but this should work :

$data_json = '[{"1": "[email protected]_1.jpeg"}, {"2": "[email protected]_2.jpg"}, {"3": "[email protected]_3.jpg"}, {"4": "[email protected]_4.jpg"}, {"5": "[email protected]_5.jpeg"}]';
$data = json_decode($data_json, TRUE);
unset($data[1]);
$data_to_save = json_encode($data);

 $postImage = PostImage::where('post_id', $post->id)->update(["image" => $data_to_save]);

Vilfago left a reply on JSON Update Query Runs Nothing Changes In Database?

"image->1" should be the database column. I think it's not.

03 Feb
3 months ago

Vilfago left a reply on How To Display Category Where Id = 1?

public function index ()
{

    $webDesigns = About::with('categories' =>function($q) { $q->where('id', '1');}])->get();
    return view('Home.index', compact('webDesigns'));
}

01 Feb
3 months ago

Vilfago left a reply on Laravel 5.6 Eloquent Relationship

You cannot have this type of relation, as you will loose the information of TeamMatch in HomeTeam (or AwayTeam).

You need to set a HasManyThrough (or two, one for home team, one for away team) in your TeamMatch model (but not sure it will work)

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

Vilfago left a reply on Laravel Framework Eloquent Relationship Query

Could you put all the relevant code in a block code (begin and end with ``` ) ?

I don't see you foreach loop, the issue could be there.

Vilfago left a reply on How To Set An Array Globally Available In Laravel?

Yes, you have "Uk" in your class due to normalize, and look for "UK". So I guess you're in "rest of the world"

Vilfago left a reply on Laravel Framework Eloquent Relationship Query

You retrieve only the first business with first(), so you only have one contract. Try get().

Vilfago left a reply on Getting Permissions Per User Object

It depends which package you use ;)

Vilfago left a reply on Foreach

If you want only camping in vestfirdir, you can add a where clause to your database query.

Vilfago left a reply on Why Doubled Name In Route Name ?

Because it's a resource, so its call departments.index, department.create, etc.

Remove as => 'department

31 Jan
3 months ago

Vilfago left a reply on Laravel 5.6 Eloquent Relationship

Because of the relation is not properly set

TeamMatch Model

public function homeTeam()
{
    return $this->belongsTo(Team::class, 'home_team_id');
}

public function awayTeam()
{
    return $this->belongsTo(Team::class, 'away_team_id');
}
public function teamMatchEvent()
{
    return $this->hasMany(TeamMatchEvent::class, 'team_match_id');
}

TeamMatchEvent Model

public function teamMatch()
{
    return $this->belongsTo(TeamMatch::class, 'team_match_id');
}

public function team()
{
    return $this->belongsTo(Team::class, 'team_id');
}
30 Jan
3 months ago

Vilfago left a reply on Many To Many - Query

You should have the id of the company with $customer->companies, and it's the same than the company_id in the pivot.

Vilfago left a reply on Setting Up A Multi-Vendor Product Relationship

Maybe provide a concrete example, I'm not sure to understand the need of the master table.

Vilfago left a reply on Laravel 5.6 Eloquent Relationship

$last_match_results = TeamMatch::with('teamMatchEvent.team')->first();