Borisu

Experience

104,210

45 Best Reply Awards

  • Member Since 1 Year Ago
  • 726 Lessons Completed
  • 23 Favorites

15th August, 2018

Borisu left a reply on How To Search Follower By Username Or Email • 1 month ago

I believe you don't need to use the "%" in the $term. Omit it and try again.

Borisu left a reply on Fully Rely On API? • 1 month ago

In my humble opinion it would be a disaster... Think of the overhead created by the HTTP requests to your own application. Each time you need even basic models you would go out over the wire and ask for it.

Depending on your application you can just check if the request is expecting json and return the model directly. Laravel will automatically serialize it as json for you. If you anticipate to grow to a large app you might consider implementing a full API layer. This is rarely the case, so just do the minimal amount of work. I have personally used this method in production code and it works fine for quite large installations.

3rd August, 2018

Borisu left a reply on How Can I Test That The Authorize Method Has Authorized The User To Do The Request. • 1 month ago

My personal preference when testing many roles is to still keep them in separate functions. This way you have a very verbose description of the roles and what they can do.

Having said that the method you suggested is also valid. I would just create four users:

$sa = create('App\User', ['UserType' => 'SuperAdmin']);
...
$users = collect($sa, $admin, $mediaUser, $iAdmin);

foreach ($users as $user) {
    $this->assertTrue($user->can('create', Media::class));
}

This way you can just call the can method directly on the user and assert they can do something.

2nd August, 2018

Borisu left a reply on How Can I Test That The Authorize Method Has Authorized The User To Do The Request. • 1 month ago

Well you can sign in a user who can do whatever you authorize and then assert that the action succeeded.

In a test:

$user = factory('App\User')->create(['can' => 'update_comments']);  // or however you do that in your database...
$this->actingAs($user)
    ->post(route('update.comment'), ['comment' => 'blah blah'])
    ->assertRedirect(route('comments'));

Something along these lines should be enough. If you provide some more details we can work it out exactly.

1st August, 2018

Borisu left a reply on Blades Can Access $errors, So How To Access It From Controller? • 1 month ago

The views get the errors variable through a view composer, or more accurately it is inserted by the View class into each and every instance of a view.

You need to access the errors through some kind of provider instance. In your controller it is usually the Validator class.

18th July, 2018

Borisu left a reply on How To Override The Created_at Attribute Of The Notifications Records To Match A Specific Timestamp? • 2 months ago

You can hook into the creating event of the notification and change any data you like.

Borisu left a reply on Check The Model's Column Names • 2 months ago

@jurios Hi, you can get all of the columns:

DB::getSchemaBuilder()->getColumnListing('users')

Regards

30th May, 2018

Borisu left a reply on User Permission Using Service Repository • 3 months ago

In that case you can check if the user has a permission, as it is a table in your database. You can use where to experiment and finally even add a scope to filter the data.

Borisu left a reply on Routing Under One Parent Folder • 3 months ago

Yes but then you will have a show method on the controller instead an index:

Route::group(['middleware' => ['auth'], 'prefix' => 'fixtures'], function() {
    Route::get('/', '[email protected]');

    Route::get('/competition/{competitionId}', '[email protected]');

    Route::get('/hometeam-vs-awayteam/{hometeamId}', '[email protected]');
});

You can find more here: https://laravel.com/docs/5.6/routing#route-parameters

29th May, 2018

Borisu left a reply on Loop Through Axios Data To Display Thumbnails • 3 months ago

Well you have to parse the html you get back and pick out the href's of the anchor tags. You can then give the response data to cheerio (https://github.com/cheeriojs/cheerio) and play around with it. It should be fairly easy to get the images since they all share the itemprop "thumbnailUrl". At this point you have a list of valid html, just append it to your page and you're done.

Borisu left a reply on Undefined Variable: Peaple • 3 months ago

I'm with tykus on this, I think you're visiting the wrong url, where there is no variable people (nor peoples). And by the way peoples is not correct english, since people is already plural, might want to be careful with that...

Borisu left a reply on Conditionally Pushing Event Listeners To Queue • 3 months ago

Did you register it properly? Having the class is not enough.

Borisu left a reply on Access Multiples Authenticate Guards On Subdomain? • 3 months ago

Watch this video it will clear it all up:

https://www.youtube.com/watch?v=iKRLrJXNN4M&t=1706s

Borisu left a reply on User Permission Using Service Repository • 3 months ago

It depends what kind of permission-system you're using. Your own, Voyager or something else?

Borisu left a reply on Routing Under One Parent Folder • 3 months ago

You can do something like this:

Route::group(['middleware' => ['auth'], 'prefix' => 'fixtures'], function() {
    Route::get('/', '[email protected]');

    Route::get('/competition', '[email protected]');

    Route::get('/hometeam-vs-awayteam', '[email protected]');
});

The prefix keyword will put the fixtures in front of all links in the group. If you would like to create some named routes you can use 'as => 'fixtures.' To prefix the names with fixtures. <- note the dot.

You can name the controllers anything you want ;) and yes it's actually a good idea to have three separate controllers :)

Borisu left a reply on Undefined Variable: Peaple • 3 months ago

You missed an s in peoples

// you have
url = "{{ route('peoples.edit', ['id' => $people->id]) }}" + '*apiPrefix*' + '/peoples/' + id + '/edit';

// should be
url = "{{ route('peoples.edit', ['id' => $peoples->id]) }}" + '*apiPrefix*' + '/peoples/' + id + '/edit';

24th May, 2018

Borisu left a reply on Search The Database But Does Not Pass The Value • 4 months ago

@GeorgeMartins it seems you have different names: one is modelo_id and the other cliente_id Did you change it? If the request name is differs from the validation name, it won't pass validation and you'll just get redirected back to your page.

Is your intended process as follows: User visits page where they see a form, they select something in the form and post it to the server. Based on the input you search for a result in your tables and display that to the user. (So if this is true, we might be looking at a different problem).

21st May, 2018

Borisu left a reply on Hello Newbie Here • 4 months ago

@tykus awesome tip :)

20th May, 2018

Borisu left a reply on Search The Database But Does Not Pass The Value • 4 months ago

@GerogeMartins Yes, sorry about that. pluck actually gives back an array, so it wouldn't work as I suggested. I used Client::get(['id', 'razaosocial']) for testing, which will give you back a collection of models. What tykus said will work correctly. (So this is just personal preference at this point).

Back to the main problem. Did you check your validation? Can you just dd(request()->all()) in your controller and check if the value is inside?

Check your middleware as well. Might be something fishy there, if the dd() doesn't show the value.

18th May, 2018

Borisu left a reply on Search The Database But Does Not Pass The Value • 4 months ago

ouhare's suggestions is not correct as it will pass the array index into the form value and not the actual id. The correct version is:

\@foreach ($cliente as $client)
    <option value={{ $client->id }}>{{ $client->razaosocial }}</option>
\@endforeach

Also if the value is not fillable you'll get an error saying 'Cannot insert into table etc etc.' showing the query to the db with an empty value for cliente_id.

The only other thing I can think of right now is maybe form validation. @GeorgeMartins do you have any and what does it look like?

Borisu left a reply on Laravel Queues • 4 months ago

In that case you can just restart the queue as it will not persist the list of jobs.

17th May, 2018

Borisu left a reply on Laravel Queues • 4 months ago

Theoretically yes, but why would you want to do that? If the queue begins with a 1000 jobs and finished 500 in 24 hours then you'll have only 500 jobs left in the queue. As soon as a job is done it's removed from the list of jobs. You just leave the queue open forever and it will process jobs until you kill the application. No need for any manual action.

Borisu left a reply on Search The Database But Does Not Pass The Value • 4 months ago

@tykus It was just an educated guess why it might not be working.

Borisu left a reply on Check A Single Item Within A Query Scope • 4 months ago

Do you really have a field with an arrow symbol in the column name? Think about it...

If I understand you have a table with a regions column, which is supposedly a relationship. So just get the objects where the relationship returns an empty object.

Borisu left a reply on Search The Database But Does Not Pass The Value • 4 months ago

You should maybe close the form after the select ;)

Also, what exactly do you mean it shows the value, but it's not passed. Passed where?

Borisu left a reply on Laravel Queues • 4 months ago

Ok putting queues on a separate server is possible, although unless you have an obscene amount of jobs not really practical or necessary. You can have a queue for mass emails, for user notifications, for promotions and what not. This way you can just leave them running as they won't interfere with the rest of the processing. Just as a little experiment, try to fill a queue to the point it starts dropping records... You'll quickly notice it's nearly impossible for a normal applications (unless you have some bad code or something).

Borisu left a reply on What Is The Standard Practice For Laravel + VueJS Authentication? • 4 months ago

Hey, a very simple rule to go by. Use the backend for business logic and the front-end for ease-of-use. You can even use the built-in authentication, it works perfectly.

Borisu left a reply on Login Redirection • 4 months ago

What you need is a middleware to check if the currently logged in user is also verified and has supplied a company name. This should be fairly easy to implement.

Borisu left a reply on Array Object Pass In Modal Using Jquery • 4 months ago

Then you'll have to find the select you wish to hydrate and append an option tag to it with the values from response. Something like

$select = $('#target-select')
response.options.forEach(function(item) {
    $select.append('<option value="' + item.value + '">' +item.name + '</li>')
}

Next time please be very precise on what you have and what you exactly need...

Borisu left a reply on Hello Newbie Here • 4 months ago

Nope. This is just for Jeffreys series.

Borisu left a reply on Trying To Setup A New Notification For Updating User Password • 4 months ago

Hi, you don't really need a whole class per se. All you need is the following (to send the token):

$user->notify(new ChangePasswordNotification());

This would be the easiest way to do what you want.

Just to clarify, are you trying to send them a confirmation link or just notify them of the change?

Borisu left a reply on Session Variables Missing After Fail Logging In. • 4 months ago

Great! Consider marking the question as done ;)

Borisu left a reply on Auth::attempt() Not Checking Password For Another Guard • 4 months ago

Ok try to dd() the current user right before you check the credentials. That way you'll see if there is something happening before you arrive at that point

16th May, 2018

Borisu left a reply on Do You Know What Is Necessary To Have A Search Autocomplete Input Text With Laravel? • 4 months ago

Per documentation (please read it): http://api.jqueryui.com/autocomplete/

you can provide an array of objects in the form

[{label: 'Label', value: 'Value'}, ...]

Where label is displayed to the user and value is the value inserted into the input box.

$conferences = $conferences->map(function($conference) {
    return ['label' => $conference->name, 'value' => $conference->id];
});

This is a very very basic autocomplete functionality, if you want to show the customer in which field his query is valid, you'll have to pay for a service like Algolia.

Borisu left a reply on Do You Know What Is Necessary To Have A Search Autocomplete Input Text With Laravel? • 4 months ago

So you're getting the double conf conf because you're transforming your data after you get it from the eloquent query

// in the foreach loop:
$data[] = ['id'=> $value->id, 'value' => $value->name . " " . $value->name];

The second error is also connected to this data transformation, since the city key is no longer present in the result, you cannot show it. I would suggest you pass back the collection directly.

return response($conferences);

What i meant with checks is to validate the user input before doing anything with it. So in fact the first thing you do in your controller is:

$request->validate([
    'term' => 'required|alpha'
]);

It's best if you just use a custom rule for the input validation...

Borisu left a reply on Vue Compiled Mixed With Runtime • 4 months ago

Well you have a lot of choices. You can make a single generic wrapper component with the functionality you need. You might use inline templates. You just might need some vanilla js... Maybe if you post some of the concrete problems you want to solve it will be easier to give a comprehensive in-depth reply ;)

Borisu left a reply on Auth::attempt() Not Checking Password For Another Guard • 4 months ago

Did you logout first? The guard usually first checks if someone with the same id is already logged in. Next step would be to check if your guard is properly setup...

Borisu left a reply on Pagination Page 2 Return Page 1 On Production Server • 4 months ago

Maybe a silly question, but do you have more than 10 values in the list?

Borisu left a reply on Trying To Setup A New Notification For Updating User Password • 4 months ago

You can open the PasswordBroker to see exactly what is happening there. Since the sendResetLink is a method on that class and the class is not macroable, your best bet is to make your own class with the functionality you need which implements the PasswordBroker class. This way you can extend it and keep some of the nice functionality. You could just try to put the logic for the separate steps in your controller, make it work there and when it's done start extracting to dedicated classes. This is usually an easier approach to complex multi-step processes (in my opinion).

Borisu left a reply on Session Variables Missing After Fail Logging In. • 4 months ago

You're using the flash function, which will show the flash message only to the next view in the chain. Usually using middleware you go through a couple of layers and the flash gets lost. Try saving the message to the session instead of flashing it. If it works you'll know it's a problem with the amount of layers you have in your app...

Borisu left a reply on Do You Know What Is Necessary To Have A Search Autocomplete Input Text With Laravel? • 4 months ago

Well on the back-end you're just making a query to your database for the fields you mentioned. So a super simplified version might look like:

public function search(Request $request) {
    $userQuery = $request->get('q'); // where "q" is the name of the input you use
    $conferences = Conference::where('name', 'like', $userQuery)->get();
    return view('your.view', compact('conferences'));
}

This is the back-end. For each letter the user inputs you'll fire a request to your server and trigger this search function. It will return a collection of the conferences which correspond to it. The problem is you don't want to fire a request every time someone types in a letter. There some functionality like the lodash debounce function comes into play and will wait for some time before sending a request to the server, thus minimizing the load on the back-end. To extend the search you can do:

$conferences = Conference::where('name', 'like', $userQuery)
    ->orWhere('city', 'like', $userQuery)
    ->get();

Hope this helps. Don't forget this is absolutely the minimal amount of work to get a result. You should secure with checks and what not.

5th March, 2018

Borisu left a reply on How To Hide Laravel-debugbar In A Specific View. • 6 months ago

You have to do this in the AppServiceProvider. There in the register method you can check if the environment is production and hide it.

if ($this->app->isLocal()) {
    $this->app->register(\Barryvdh\Debugbar\ServiceProvider::class);
}

Similarly you can check if you're on a specific view:

if (! Route::is('some.route', 'another.route')) {
    $this->app->register(\Barryvdh\Debugbar\ServiceProvider::class);
}

I'll leave the optimization to you tho ;)

3rd March, 2018

Borisu left a reply on The Route::is() Method - How To Find Out ? ... • 6 months ago

You don't actually need a method on the class, just get the name of the current route and use in_array('route.name', ['routes', 'more.routes'])

23rd February, 2018

Borisu left a reply on Is It Possible To Inject A Variable Into Route Group Which Is Common For All Inside Routes? • 7 months ago

Yes, but not in the routes. You can use view composers to make a variable available to a certain "group" of views. You can specify which vies will get access to the data, or use wildcards to specify all etc.

https://laravel.com/docs/5.6/views#view-composers

Borisu left a reply on I Want To Build One-to-one Private Realtime Chat With Firebase • 7 months ago

Just check this out: https://laracasts.com/series/get-real-with-laravel-echo Should have everything you need to get started.

Borisu left a reply on Remove URL Query Parameters Form Url • 7 months ago

You're getting the query string because your form method is get. You either just use an anchor tag, or a post request.

<a href="{{ route('user.showProduct', $productProductOption->product->slug) }}">
or
<form method="POST" action="{{ route('user.showProduct', $productProductOption->product->slug) }}">

Borisu left a reply on Testing Mailables Attachment • 7 months ago

Check if you're performing your assert in the right order.

Borisu left a reply on Testing Mailables Attachment • 7 months ago

You don't need to mock the storage function in the mail class, because you have mocked the global storage class. This means any operations related to storing will go to the fake.

Borisu left a reply on Laravel Append Attribute Not Working • 7 months ago

Hi, custom attributes are not automatically appended. You can call

protected $appends = ['averageRating'];

to include it whenever you retrieve a model.

Edit Your Profile
Update

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