Vilfago

Vilfago

Member Since 1 Year Ago

Neuch√Ętel

Experience Points
95,310
Total
Experience

4,690 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
123
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    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 Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 20
95,310 XP
Jun
10
4 months ago
Activity icon

Replied to Database Layout Ideas

Don't think if more than 2 users will be frequent, just think if you want it possible or not...

users table : id, name, email, password, ... conversations table : id, subject, user_id, updated_at, created_at messages table : id, message, user_id, conversation_id, created_at, updated_at, deleted_at conversation_user table : conversation_id, user_id

So you have a many to many relations between users and conversations through conversation_user, HasMany between conversation and message, and hasMany between user and message.

I added a "user_id" in conversation table if you want to store who begun/own the conversation, for a hasMany between user and conversation (not for access, but for start of them, so be carefull with the naming of this relation). In writing this post, and on the contrary of my post above, I realize this has nothing to do in the pivot table.

And when you need it in your controller

auth()->user()->load('conversations');

Jun
07
4 months ago
Activity icon

Replied to Send Data From Controller To View Depending On The User

Your first line when you fetch all Application data is useless. Are you sure that in application table, you have a dealer_id column ?

For helping more, we need to have a view on which column you have in application table.

Did you take time to read about relations and policies in laravel documentation? It could help you on this matter.

May
26
4 months ago
Activity icon

Replied to Database Layout Ideas

A many to many relationship. Then you can even have conversation with more than 2 people in it. And if you want to track who started it, you can put it in the pivot table.

May
17
5 months ago
Activity icon

Replied to 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...

May
09
5 months ago
Activity icon

Replied to Method Illuminate\Support\Collection::paginate Does Not Exist

You can simulate the paginate with take and skip

May
03
5 months ago
Activity icon

Replied to 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.

Mar
08
7 months ago
Activity icon

Replied to 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);
Feb
27
7 months ago
Activity icon

Replied to 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();

Feb
14
8 months ago
Activity icon

Replied to 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 or something similar ? You will have every parameter in the request, no matter the order they are provided. (Edit : see Cronix answer below for more information on that)

Activity icon

Replied to 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

Activity icon

Replied to How Can I Save Duplicate Record In Laravel ?

Yes, if it works :)

But it could be better to have two different name for the variables.

Activity icon

Replied to How Can I Save Duplicate Record In Laravel ?

Try this

$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();
Activity icon

Replied to Is This The Right Way Of Editing A Form?

You can also upgrade to 5.7 :)

Activity icon

Replied to 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

Activity icon

Replied to 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

Feb
13
8 months ago
Activity icon

Replied to 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]']);
Activity icon

Replied to 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 ?

Activity icon

Replied to 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.

Activity icon

Replied to 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 ?

Feb
12
8 months ago
Activity icon

Replied to 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.

Activity icon

Replied to A Simple Question About Posting A Form

If the objective of your form is creating new posts (i.e storing them in a database), yes it's the right route for that.

Activity icon

Replied to 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

Activity icon

Replied to 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

One user have many national cards (not sure ?), user have many bank cards (probably), etc.

You can use a polymorphic relation if needed ( https://laravel.com/docs/5.7/eloquent-relationships#one-to-many-polymorphic-relations )

Activity icon

Replied to 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`

Activity icon

Replied to 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
Activity icon

Replied to How To Populate Timezone Selectbox

So it is solved ?

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

Activity icon

Replied to Create Pivot Table For One To Many Relationship

Yes, but why ?

The easiest way is to manage it as a ManyToMany relations.

Activity icon

Replied to 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 ? I think PHPStorm complain about addind a number to a string.

            //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;
            };

if $nrcan_consump_records_options is a collection, you can use sum() method : https://laravel.com/docs/5.7/collections#method-sum

Feb
11
8 months ago
Activity icon

Replied to 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); //explode all names to different arrays
    $numberOfNames = count($nameArr); //count the number of names
    $name = ''; //we reset the name
    for($i = 0; $i < $numberOfNames ; $i++){ 
        if($i == $numberOfNames - 1){
            $name .= $nameArr[$i]; //It's the last name, we take it full
        }else{
            $name .= $nameArr[$i][0].'.'; //it's not the last name, we take the first character and add a .
        }
    }
}

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).

(better solution to find the last element of the loop for last php version: https://stackoverflow.com/a/8780881 )

Activity icon

Replied to 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.

Activity icon

Replied to 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.

Feb
07
8 months ago
Activity icon

Replied to 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).

If it's the case, try :

public function startImportProcess($language, $id) {
        $importer = Importer::find($id);
Activity icon

Replied to How To Custom Button Text On Resources

Yes

<button>Your custom text</button>

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

Feb
06
8 months ago
Activity icon

Replied to How To Get Multiple Images

put your code between two ```

It will be readable like that :)

Feb
04
8 months ago
Activity icon

Replied to 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.

Activity icon

Replied to 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 ?

Activity icon

Replied to 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]);
Activity icon

Replied to JSON Update Query Runs Nothing Changes In Database?

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

Feb
03
8 months ago
Activity icon

Replied to 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'));
}

Feb
01
8 months ago
Activity icon

Replied to 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

Activity icon

Replied to 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.

Activity icon

Replied to 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"

Activity icon

Replied to Laravel Framework Eloquent Relationship Query

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

Activity icon

Replied to Getting Permissions Per User Object

It depends which package you use ;)

Activity icon

Replied to Foreach

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

Activity icon

Replied to Why Doubled Name In Route Name ?

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

Remove as => 'department

Jan
31
8 months ago
Activity icon

Replied to 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'); //Your foreign key was wrong
}

TeamMatchEvent Model

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

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

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