Vilfago

Experience

43,780

55 Best Reply Awards

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

20th July, 2018

Vilfago left a reply on Can Someone Review My Eloquent ? • 1 day ago

I'm not sure your code is working, due to the relations belongsTo (the column is probably category_id instead of id), amd that you try to retrieve your relations as if it was an array instead of an object...

But if it's work, good for you. If not, please give us some comments (what you tried to achieve, which errors occur, ...)

13th July, 2018

Vilfago left a reply on Eloquent Relationship: Garage - Car - Security • 1 week ago

I guess "who can do more can do less".

11th July, 2018

Vilfago left a reply on Custom Authentification Query • 1 week ago

Vilfago left a reply on Using HasMany() • 1 week ago

You have to use belongsTo for this relation.

Have a look on this page : https://laravel.com/docs/5.6/eloquent-relationships

Vilfago left a reply on BelongsToThrough Equivalent Or HasManyThrough Using Pivot Table Autoincrement Key • 1 week ago

https://laravel.com/docs/5.6/eloquent-relationships#eager-loading

You set your relations from Class to StudioClass (named studioclass) and from StudioClass to Studio (named studio)

and then you can get data from studio table like that : ``` $class = Class::with('studioclass.studio')->find($id);

Vilfago left a reply on BelongsToThrough Equivalent Or HasManyThrough Using Pivot Table Autoincrement Key • 1 week ago

I don't see how you can set a direct relation between Studio and Class, however you can retrieve data with nested eager loading.

Vilfago left a reply on BelongsToThrough Equivalent Or HasManyThrough Using Pivot Table Autoincrement Key • 1 week ago

Why didn't you put all information you had currently in studio_classes table in classes table, and just add "studio_id" in classes table.

And then, you just have a "belongsTo" relation between ClassModel and Studio.

10th July, 2018

Vilfago left a reply on Best Approach To Get All Polymorphic Models • 1 week ago

Maybe with a global scope addSelect to rename "title" to "name" in your post model.

https://laravel.com/docs/5.6/eloquent#query-scopes

8th July, 2018

Vilfago left a reply on Route To Controller • 1 week ago

You have to set all your routes in the route file, but you can link to a controller action in the view using action().

https://laravel.com/docs/5.6/helpers#method-action

But it works only if the controller method is linked to a route

5th July, 2018

Vilfago left a reply on Why This Returns A Model?! • 2 weeks ago

$user->admin->branches->where('id', $id);

3rd July, 2018

Vilfago left a reply on Pivot Table • 2 weeks ago

As your pivot table don't have the "convention" name, you should specify it in your relation. And the related column too.

https://laravel.com/docs/5.6/eloquent-relationships#has-many-through Last example, before polymorphic relations

Vilfago left a reply on Pivot Table • 2 weeks ago

put the code between ``` tags

Vilfago left a reply on My Laravel Is Not Working • 2 weeks ago

So what did you change ?

Vilfago left a reply on Route [add.answer.create_answer] Not Defined • 2 weeks ago

your route name is only "add_answer", so in your view (blade file)

<a href="{{ route('add_answer',['assignment_id' => $assignment->id]) }}" class="btn btn-xs btn-primary">@lang('quickadmin.view')</a>

Vilfago left a reply on Restart Numbering In View • 2 weeks ago

if it's only for display sequential number, you don't need to use ID from DB

@php
$i = 1;
@endphp

@foreach($rows as $key => $row)
    {{ $i }} / {{ $row->name }}
    @php
        $i++;
    @endphp
@endforeach

2nd July, 2018

Vilfago left a reply on RESTful Actions • 2 weeks ago

by only updating with specific

so PUT/PATCH for update ?

Vilfago left a reply on Everything I Add New Goes To The Right Side • 2 weeks ago

Your css class don't seem to be from bootstrap. Which css framework do you use?

1st July, 2018

Vilfago left a reply on Suggestion On ERP Development • 2 weeks ago

Choose in considering that :

  • it should be fast as possible, as you have to manage a lot of data (often no possible aggregation in an ERP)
  • it should be easily customizable for each buyer, as each of these will have specific request
  • Your team must be efficient with the languages, as you will encounter a lot of tricks in coding that.

I don't think clients will ask in which language it's done, but only what they need to run it (nothing if it's on cloud, and what if it's on prem).

30th June, 2018

Vilfago left a reply on Incremental ID Vs UUID • 2 weeks ago

It's depend from a lot of things, such as db (mysql, postgresql, mongodb, others), the size, and so on...

But I think I'll go with UUID to eassily managed merge of data in the future.

Vilfago left a reply on Where Multiple Clause OrWhereIn Array • 2 weeks ago

$rs = DB::table('tableUser')
            ->select('name')
            ->where(function($q) {
                $q->where(function($q){
                  $q->where('fid', '=', $this->argument('fid'))
                    ->where('type', '<', 4);                
            })
                ->orWhereIn('id', $Array);
            })
            ->get();

Vilfago left a reply on Automatically Insert Created_at And Updated_at • 2 weeks ago

Inserting by migrations or filled when you save data?

Vilfago left a reply on Multilevel Relationship WhereHas On Eloquent Model • 2 weeks ago

Good to know. I thought that with only with you will retrieve all projects but only a part of tasks.

Vilfago left a reply on Multilevel Relationship WhereHas On Eloquent Model • 3 weeks ago

$project = Project::whereHas('tasks', function($query){
         $query->whereHas('tags', function($query) {
             $query->where('tag_id', 1);
        });
    })->get();

It should filter projects, but not sure you will retrieve tasks, so I add a with just in case

$project = Project::whereHas('tasks', function($query){
         $query->whereHas('tags', function($query) {
             $query->where('tag_id', 1);
        });
    })->with(['tasks' => function($q) {
        $q->whereHas('tags', function($query) {
             $query->where('tag_id', 1);
        });
    }]);
    ->get();

Vilfago left a reply on Multilevel Relationship WhereHas On Eloquent Model • 3 weeks ago

You query to find only one project, if it has a tag with id 1, and then return everything.

But I'm not sure what you mean by

with all its tasks and tasks with tags with only id of 1

You want all task or only a part?

29th June, 2018

Vilfago left a reply on One To Many To One Relationship • 3 weeks ago

Set your one to many (company -> employees) and one to one (employee -> moto) relation in the related models.

You can retrieve them with nested relations https://laravel.com/docs/5.6/eloquent-relationships#eager-loading

$companies = Company::with('employees.motorcycle')->get();

25th June, 2018

Vilfago left a reply on Migration Array With Relation • 3 weeks ago

If you set the relation in your models, you can use the save method as explained here : https://laravel.com/docs/5.6/eloquent-relationships#the-save-method

However, are you sure that each ingredient will be used only for one recipe ? I think a many-to-many relations could be better.

Vilfago left a reply on Markdown VS HTML + Purifier? Please Help Me Decide! • 3 weeks ago

I coded myself the converter, but it's very similar to kaimallea (unless I didn't use regex for simple tag such as [b] => , but only str_replace().

I just used isU as regex converter instead of is, so add the "ungreedy" mode. I don't see any issues in nested tags, but didn't try very complex code. Have you any example of failed nested tags ?

If it passes, I can share you my work.

Vilfago left a reply on Return Posts Ranked By Number Of Associated Comments. • 3 weeks ago

https://stackoverflow.com/questions/24208502/laravel-orderby-relationship-count

Seems we can do all in once :

$posts = Post::withCount('comments')->orderBy('comments_count', 'desc')->take(10);

Vilfago left a reply on Return Posts Ranked By Number Of Associated Comments. • 3 weeks ago

A different way, but the sort will be performed outside the DB :

$posts = Post::withCount('comments')->get();

$posts = $posts->sortByDesc('comments_count')->values();

https://laravel.com/docs/5.6/eloquent-relationships#counting-related-models https://laravel.com/docs/5.6/collections#method-sortbydesc

24th June, 2018

Vilfago left a reply on How Can I Install Bootstarp With Laravel 5.6 Using Npm? • 3 weeks ago

Using npm, you will have only one file for all libraries, instead of many.

23rd June, 2018

Vilfago left a reply on What Cause <?php<!doctype Html> Or <!--?php<!doctype Html--> In Laravel ? • 3 weeks ago

Not sure, but I think you need a 'spacecharacter after<?php` such as new line or whitespace

22nd June, 2018

Vilfago left a reply on Markdown VS HTML + Purifier? Please Help Me Decide! • 4 weeks ago

I choose BBcode, I use htmlspecialchars on user input, and then convert bbcode to html.

So no purifier on my side, but a white list of bbcode that could be converted (with some regex).

Vilfago left a reply on Quick Question: About Relationship • 4 weeks ago

Eloquent assumes that the foreign key should have a value matching the id (or the custom $primaryKey) column of the parent. In other words, Eloquent will look for the value of the user's id column in the user_id column of the Phone record. https://laravel.com/docs/5.6/eloquent-relationships

If your model is not plural, it should be tag_id

Vilfago left a reply on Laravel \ Socialite \ Two \ InvalidStateException • 4 weeks ago

I don't see the error you get.

Vilfago left a reply on Create A Multidimensionnal Array For Retrieving Opening Hours Out Of A Laravel Database • 4 weeks ago

There's probably a better way, but you can have a try with flatten on the collection https://laravel.com/docs/5.6/collections#method-flatten

Just find the relevant depth to pass at argument

Vilfago left a reply on Laravel \ Socialite \ Two \ InvalidStateException • 4 weeks ago

You will have to tell us more...

Vilfago left a reply on Problem With Method "show" In My Controller • 4 weeks ago

He don't looks for id but for id_autotradecatalogs.

Try http://test.ru/public/autotradecatalogs/36 and you will have something.

Vilfago left a reply on Markdown VS HTML + Purifier? Please Help Me Decide! • 4 weeks ago

As far as I know, markdown will be converted to html for being displayed... so you can have the same security for embedded videos of you configure correctly your purifier.

Purifier should work with a "white list" of things allowed, and escape everything else, so if it's well configured, you should be safe...

I don't know for markdown, but you can find WYSIWYG editors in BBcode. And you can often add many labels to support what you want, and convert it to html in the back-end.

I think you should try to find the one with the most relevant UI for your users, they will never been interested if it's markdown, bbcode or html in the back. That's your job ;)

Vilfago left a reply on Create A Multidimensionnal Array For Retrieving Opening Hours Out Of A Laravel Database • 4 weeks ago

What do you get before converting to an array?

21st June, 2018

Vilfago left a reply on How To Add Data To Another Table After The Current Data Has Been Added • 4 weeks ago

Seems the doc says "yes it is"

https://laravel.com/docs/5.6/eloquent-relationships#the-save-method

foreach($request->images as $image)
{
    $gallery->images()->save($image);
}

Vilfago left a reply on How To Add Data To Another Table After The Current Data Has Been Added • 4 weeks ago

When you do $gallery->save() the id is returned.

So you can use $galleryImage->gallery_id = $gallery->id

Vilfago left a reply on Uploaded To A Server But Public • 4 weeks ago

Could you edit the DNS in order of your root folder being the public folder of laravel ? It could be a solution

Vilfago left a reply on Show Everything From 3 Tables Where Not In 1 Table • 4 weeks ago

It could be easier to consider your "count table" as the pivot table in a many-to-many relationship between projects and user.

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

And then, you just have to querying relationship absence with whereDoesntHave https://laravel.com/docs/5.6/eloquent-relationships#querying-relationship-absence

Something like :

$projects = App\Project::whereDoesntHave('counts', function ($query) use($user_id) {
    $query->where('user_id', '=', $user_id);
})->with('images')
->get();

Vilfago left a reply on Can I Install Laravel 5.6 On Windows 7 • 4 weeks ago

You can also try Laragon, it's easy to install all you need to run Laravel for dev on Windows.

Vilfago left a reply on Storing Images Using Storage Not Working For Me At All • 4 weeks ago

Was the symlink created in the public folder (root/public/) ?

Did you find the file on your server ?

Vilfago left a reply on How To Get Defined Accessor When Using User::select('custom_attribute') • 4 weeks ago

It will be created only when you call it.

echo $message->short_body.'<br />';
}

Vilfago left a reply on Why Use PUT | PATCH | DELETE In Laravel • 4 weeks ago

Due to REST

https://www.codecademy.com/articles/what-is-rest

It helps knowing what you do in speaking with the API

Vilfago left a reply on Laravel Undefined Variable: • 4 weeks ago

For information, you don't need to transform the result to an array with toArray to loop your result. The collection instance is traversable.

You just have to write $host->pavadinimas instead of $host['pavadinimas']

Edit Your Profile
Update

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