Borisu

Experience

79,700

37 Best Reply Awards

  • Member Since 11 Months Ago
  • 557 Lessons Completed
  • 21 Favorites

13th November, 2017

Borisu left a reply on Roles Vs. Multi-auth In Laravel 5.5 • 4 weeks ago

Are the properties on the Patient and Practitioner very different? If so you'll only benefit from two separate models and thus a multi-auth system is a nice way to go about it.

If the two models are basically the same, then you should consider just using a model User with a type prop = patient or practitioner, or some kind of role based system. Then you avoid polymorphism and multi-auth altogether.

26th October, 2017

Borisu left a reply on Validation With Different Error Messages - Is It Possible In Form Requests • 1 month ago

@laravelandme Hi, first of all you don't need to split the code like that. Just use one validation rule, because the validator will fail on the first rule and continue. To use custom messages you can set them as a third argument in your validator:

$validation = Validator::make($request->all(), [
    'Name' => 'required|unique:users,name',
    'Email' => 'required|unique:users,email',
    'Date_of_birth' => 'required|date_format:"Ymd"',
    'Code' => 'required|exists:codes,name'
], [
    'Name.required' => 'Missing input in the Name',
    'Email.required' => 'Missing input in Email'
    ...
    '*.unique' => 'Invalid input'
]);

I hope this clears things up. Then in your conditional you can check the errors for a missing input error or for invalid input error etc.

I would really suggest to not use custom messages unless really necessary.

18th October, 2017

Borisu left a reply on IP To Location • 1 month ago

17th October, 2017

Borisu left a reply on Ffmpeg Generating A Video From Images • 1 month ago

Yeah I checked the source code and there is nothing there, but you can just use something like the symfony process command http://symfony.com/doc/current/components/process.html It ships with Laravel, I even think they have a wrapper for it, but I'm not sure what it's called.

Borisu left a reply on Phpunit Error • 1 month ago

Check the filename as well as the class name, after that check that you're staging your test correctly:

/** @test */
public function something_to_test()
// or

public function testSomething()

Check you have access to phpunit, it's the correct version etc.

Worst case scenario is to just do a clean install in another dir and test it there. If it doesn't work there you have a general problem on your system.

16th October, 2017

Borisu left a reply on SearchController To Parse Through Multiple Databases • 1 month ago

You should be able to edit the guard to allow for your connection, but I'm not sure how to do that.

Borisu left a reply on Ffmpeg Generating A Video From Images • 1 month ago

Your question is better asked on the github page of the provider...

In any case it seems to me the functionality you desire is not implemented.

Borisu left a reply on SearchController To Parse Through Multiple Databases • 1 month ago

You missed a semicolon:

    $result = $users->merge($business)

Borisu left a reply on Set Up Laravel Project In A Subfolder Of An Existing Site On Nginx Server • 1 month ago

Well when you try to make multiple sites available on the same port you need a whole server block per site, meaning you have to repeat the whole location / and location \.php$ stuff. Within the server block you will specify a server name which will ultimately decide via DNS which server you're trying to call. Your solution will never work in it's current form.

Borisu left a reply on Phpunit Error • 1 month ago

Well it says the class ExampleTest is missing and not the file, so go in and check if the class is messed up.

Borisu left a reply on SearchController To Parse Through Multiple Databases • 1 month ago

Ok so I was actually mistaken with the on method. The simple way to go about this would be like this:

In config/database.php

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

Note: the driver here is sqlite just to keep it simple... Use anything you want.

On the Business model:

protected $connection = 'business';

In the migration:

Schema::connection('business')->create(/* usual stuff */);

Now you can do this:

$business = Business::where('username', 'LIKE', $query)->get();

/* merge the results */

$newCollection = $users->concat($business);

The new collection will hold mixed object types so be careful.

Borisu left a reply on SearchController To Parse Through Multiple Databases • 1 month ago

You could do the exact same query on the other database with the on('db_name') and then merge the two results.

15th October, 2017

Borisu left a reply on HasManyThrough WithCount GruopBy • 1 month ago

Ah right, I missed that. As long as it works, good job.

13th October, 2017

Borisu left a reply on How To Add Headers To Test? • 1 month ago

You can also directly chain the assertion like so:

public function testCreateMethodSuccess()
{
    $this->json('POST', '3/users', ['name' => 'Sally'], ['HTTP_Authorization' => $this->token]);
        ->assertStatus(422);
}

cheers

12th October, 2017

Borisu left a reply on Only And Except Doesn't Not Work With ResourceCollection • 2 months ago

@EmilMoe nope pluck will show the $key $value pairs as requested. Just use map to remove null values.

Borisu left a reply on Seeds, Factories, And Random Relational Data... • 2 months ago

Why do you think the solution I gave you is not elegant?

  1. Generate couple of hundred users (UsersSeed.php)
  2. Generate threads using the aforementioned method to assign random users to threads (ThreadSeed.php)
  3. Generate replies and apply them to the threads. (ReplySeed.php)

This should run just as quick as adding a single user per thread and reply.

If you share your solution, we might discuss it and see where the bottleneck is.

Borisu left a reply on Validation With Different Error Messages - Is It Possible In Form Requests • 2 months ago

Hi,

there is a method called response which you can override. It expects an array of errors. You can try to implement your own logic there. The method looks like this:

public function response(array $errors)
    {
        if ($this->expectsJson()) {
            return new JsonResponse($errors, 422);
        }

        return $this->redirector->to($this->getRedirectUrl())
                                        ->withInput($this->except($this->dontFlash))
                                        ->withErrors($errors, $this->errorBag);
    }

You could also use the messages method to set some custom messages...

Borisu left a reply on HasManyThrough WithCount GruopBy • 2 months ago

You can add a scope to get those values

public function scopeApartmentsCount($query)
{
    return $query->withCount('apartments');
}

and for the active

public function scopeAvailableCount($query)
{
    return $query->with(['apartments' => function($q) { return $q->where('active', true); }]);
}

This should do it.

Borisu left a reply on Should I Save Avatars In The /storage/public/avatar Folder? • 2 months ago

Maybe you can use a policy for displaying the avatar. It's a clean way to go about authorizing something, like viewing a resource etc.

Borisu left a reply on Only And Except Doesn't Not Work With ResourceCollection • 2 months ago

I think what you're trying to do is called pluck:

$model->pluck(['name', 'description'])

This will for example give back the model with only the two columns.

Or just do this:

$models = Model::get(['name', 'description'])

Borisu left a reply on Is Is Really Necessary To Use Migrations To Set Your Database • 2 months ago

Probably a bad idea in the long run, but you can do whatever feels good to you ;) It shouldn't be a problem to not use migrations.

Borisu left a reply on How To Add Headers To Test? • 2 months ago

I think the correct way is to use a fourth argument in the json function:

$this->json('POST', 'users/3', ['name' => 'Sally'], ['HTTP_Authorization' => $this->token]);

Try it.

Borisu left a reply on Seeds, Factories, And Random Relational Data... • 2 months ago

You can whip up a couple of models you want to associate through relationships, then use something like this to assign them:

$parent->relation->assign($collection[rand(0, $collection->count()])

This should work just fine ;)

24th August, 2017

Borisu left a reply on Eager Loading With Multiple Constraints • 3 months ago

Oops sorry about that, you can go with the "with" method ;)

Borisu left a reply on Eager Loading With Multiple Constraints • 3 months ago

You can do:

$institute = Institute::load('address')->where('city_id', Input::get('city_id'))->where('area_id', Input::get('areas'))->get();

8th August, 2017

Borisu left a reply on Creating Notification • 4 months ago

Like so:

data: {
    visible: false
},

then you can do this

<div id="modal" :click="visible = true">
    ...
</div>

Borisu left a reply on Running Collection Methods On Query Builder • 4 months ago

I don't know how you've managed that. There are no each() and filter() methods on the illuminate/Builder and eloquent/Builder classes. When I try it, it spits out an error. My code:

Part::where('part_type', 3)->filter(function($e) { $e->serial != 'abc5'; })

BadMethodCallException with message 'Call to undefined method Illuminate\Database\Query\Builder::filter()'

Borisu left a reply on Declare Data Dynamically • 4 months ago

Ok, you can make a Vue component like so (inline or in a separate file): https://vuejs.org/v2/guide/components.html#Using-Components

So in your html you'll have something like this:

<div>
    <vue-component :isActive="{{ $laravelData }}></vue-component>
    <vue-component :isActive="{{ $laravelData2 }}></vue-component>
</div>

This component has a property called isActive, and has access to the methods you've defined. Basically something like:

Vue.component('vue-component', {
    template: '<div v-if="visibility">Component, with {{ data }}</div>',
    props: [
        isActive
    ],
    data: function() {
        return {
            visibility: this.isActive
        }
    },
    methods: {
        switchAction() {...}
    }
});

So this is just a very crappy example, but the idea is you make a blueprint of the thing you want and duplicate it many times, setting the isActive value with your php variables in the view (or whatever way you use).

Borisu left a reply on Left Menu Dependent On Top Menu Item • 4 months ago

Well I think you want some JS solution and not a php one. It's the only way to reload the content of the left menu without reloading the page. Otherwise it's simple: when hovering element A, show menu linked to element A etc.

Borisu left a reply on Declare Data Dynamically • 4 months ago

Change to a Vue component which loads it's own data. That way every instance will have the isActive prop and be responsible for it. No need to do this craziness.

Borisu left a reply on Creating Notification • 4 months ago

It's simple: bind an action to your click event on the button which changes a data value from false to true. Use that data value on your component with v-if="data-value". This is the simplest and quickest way.

7th August, 2017

Borisu left a reply on Vue Select Get Request Help • 4 months ago

I think you have to put the getOptions method inside the component code, not on the global Vue instance. Also rethink your use of the on-search binding, as this will do a query for every keystroke, which is probably not the best solution. You could use the lodash debounce method as suggested in the vue documentation.

Using axios is similar to what you have:

axios.get('url').then(response => { //code});

4th August, 2017

Borisu left a reply on Checkbox • 4 months ago

You use validator like this:

$validator = Validator::make($request->all(), [
            'chkbox_agreement' => 'accepted',
    ])->validate();
if ($validator->passes()) { // do something }

I personally would recommend

public function SendPicture(Request $request)
{
    $this->validate($request->all(), [
        'checkbox_agreement' => 'accepted'
    });

    // do whatever happens if the validation is successful
}

3rd August, 2017

Borisu left a reply on Checkbox • 4 months ago

If you don't have any JS then the request will post to the server and you should catch the error which is sent back and display it to the user. You can do this with validation. You can use a validation rule like

'checkbox' => 'accepted'

https://laravel.com/docs/5.4/validation#rule-accepted

Borisu left a reply on Route Model Binding • 4 months ago

You have to use a variable in your routes/web.php, like so:

Route::get('/user/{user}/edit', '[email protected]');

Then you can access the model

public function edit(\App\User $user)
{
    dd($user->id);
    return view('user.update');
}

28th July, 2017

Borisu left a reply on Export CSV Using Laravel 5.4 • 4 months ago

You can just get and specify an array of the fields you want:

$title_japan = TitleJapan::get(['id', 'name', $this->title->name]);

Then you'll strip the dates. You could also rename the key title_id to title_name, but you should probably check your db, as it seems it's just named wrongly.

26th July, 2017

Borisu left a reply on Extending A Polymorphic Model's X-ables Row • 4 months ago

Sadly you cannot do this easily. The best solution I have seen so far is creating a database view which you use as a normal table. I saw it in a tutorial on codecourse called Eloquent by example, you can either research SQL views or find the course and watch it. Best of luck.

10th July, 2017

Borisu left a reply on Call To Undefined Relationship [topic] On Model [App\Theme]. • 5 months ago

The error says you don't have a topic relationship... Create it and you'll be fine.

Borisu left a reply on Pivot Tables • 5 months ago

Hehe ok, great. Mark it as done ;)

Borisu left a reply on Pivot Tables • 5 months ago

Do you have a table named 'zone'?

7th July, 2017

Borisu left a reply on Eager Loading Many To Many Relationship • 5 months ago

Yes it returns the Section with a collection of all the textareas... You can access it:

$section = App\Section::where('name', 'Section A')-with('textareas')->first();
$section->textareas;

But whatever... Important thing is you solved your issue...

Borisu left a reply on Property Does Not Exist On This Collection Instance. • 5 months ago

When I try to execute a similar query I get a normal collection of object and can use it directly, without:

$items = collect($entries)->groupBy('project_id');
$items->values()->all();

You can just use your query and finish it with groupBy('project_id')

$entries = TimesheetEntry::with('client','project','timesheetTask','timesheet')
            ->where('client_id', $client_id)
            ->whereBetween('updated_at', [$start, $end])
            ->get()
        ->groupBy('project_id');

Now use the $entries collection to display info in your view.

I would also recommend to use Carbon for your $start, $end vars..

Borisu left a reply on Eager Loading Many To Many Relationship • 5 months ago

Then I was correct the first time:

Select "Section A" and display all of it's related textareas. This is done with:

App\Section::where('name', 'Section A')-with('textareas')->first()

6th July, 2017

Borisu left a reply on Property Does Not Exist On This Collection Instance. • 5 months ago

What I don't understand is why you collect a collection... Just use the groupBy on the $entries var. Tomorrow I'll run it in my test env, and tell you if I have the same problem.

Borisu left a reply on Factory Each Count • 5 months ago

Ah yes, maybe you can even try it with fresh() in combination with the first suggestion... It might just be a caching problem...

Borisu left a reply on Eager Loading Many To Many Relationship • 5 months ago

Now I get it, you don't care about which section, just that the textarea has a section...

Borisu left a reply on Show Calculation Result In Text Field • 5 months ago

Yes it's possible to read the collection, you just use raw blade syntax to assign the data->toJson() to the javascript variable you want. In your country select you can set the value of the select/option combo to the countryTravelCosts and whenever the user chooses the country the value will be the selected value. You'll have to decide if you want plain JS, or use some framework or even go the reactive way with vue or something similar.

Borisu left a reply on Property Does Not Exist On This Collection Instance. • 5 months ago

Just a wild guess, but since you're grouping by project id, shouldn't you also resolve that in your call? Meaning:

$item->project_id->client->name

Borisu left a reply on Show Calculation Result In Text Field • 5 months ago

Well do you store the countryTravelCosts somewhere in your DB? Did the user input it somewhere else?

Borisu left a reply on Eager Loading Many To Many Relationship • 5 months ago

I think I don't understand your question. Can you give a simple array example of what you want?

This is the structure I think you want, reading your post:

Illuminate\Database\Eloquent\Collection {#803
     all: [
       App\Section {#807
         id: "1",
         name: "somnul",
         created_at: "2017-06-09 12:53:28",
         updated_at: "2017-06-09 12:53:28",
         sections: Illuminate\Database\Eloquent\Collection {#818
           all: [
             App\Textarea {#822
        id: "1",
        name: "textarea1"
          },
             App\Textarea {#823
        id: "1",
        type: "textarea2"
          },
       ]
       }
     ]
}
Edit Your Profile
Update

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