Buy your loved one the ultimate gift. Lifetime gift certificates are $100 off.

andonovn

Experience

68,910

45 Best Reply Awards

  • Member Since 1 Year Ago
  • 418 Lessons Completed
  • 0 Favorites

12th December, 2017

andonovn left a reply on Sending A Form-data Post Request With Guzzle Http • 2 days ago

$http = new GuzzleHttp\Client;

$response = $http->post('https://your-endpoint.com', [
    'form_params' => [
         // data goes here
    ],
]);

andonovn left a reply on Many To Many Page Followers Efficiency? • 2 days ago

@AR Well, I didn't know if you have reasons to do this, that's why I used the word usually :)

Thumbs up for having only CRUD methods in your controllers.

andonovn left a reply on Many To Many Page Followers Efficiency? • 2 days ago

@ar From what I am seeing, it looks good to me. However, the more natural approach would be without the PageFollower model. Usually, pivot tables are not represented as Eloquent models. Then both your followings() and followers() methods would have belongsToMany instead of hasManyrelationships.

3rd December, 2017

andonovn left a reply on Request Validation From Custom Table. • 1 week ago

@VigoKrumins How about 'email' => 'required|unique:' . (new User)->getTable() ?

26th November, 2017

andonovn left a reply on Posting To Database (form Validation 101 Video) • 2 weeks ago

@Mick79 yup, that's correct :)

25th November, 2017

andonovn left a reply on How To Manage Migration Of Db Content With Existing Data? • 2 weeks ago

@resting Why not writing that logic in a migration file?

andonovn left a reply on Optimize Static Page Routes And Views • 2 weeks ago

@bnazarov@abv.bg I've just read this article which perfectly apply to your case: https://laravel-news.com/viewfirst

23rd November, 2017

andonovn left a reply on How To Push A Component Onto List Of Dynamic Components • 3 weeks ago

@benjackson Maybe like this:

let item = {
    id: 'the-new-component-id',
    type: 'the-new-component-name',
    // your other item data
};

this.feed.push(item);

andonovn left a reply on Scope Problem In User Model • 3 weeks ago

@NightM4re What are your imports (the use statements at the top) in the VentaController.php?

And make sure to return the query builder from your scopeNombre method.

andonovn left a reply on Scope Problem In User Model • 3 weeks ago

What are your imports (the use statements at the top) in the VentaController.php?

And make sure to return the query builder from your scopeNombre method.

20th November, 2017

andonovn left a reply on Optimize Static Page Routes And Views • 3 weeks ago

@bnazarov@abv.bg I think you are in the right direction in regards to the "view exists" solution. Here is how it may look:

Route::get('page/{slug}', '[email protected]'); in your routes file web.php or routes.php (depending on the Laravel version)

public function show()
{
    $template = 'pages/' . request('slug');

    if (! view()->exists($template) {
        abort(404);
    }

    return view($template);
}

^ that's of course the PageController.php

If you don't want your URL to match your view filenames, then you can add one array to map the differences. But the logic stays the same.

Another solution would be to make the pages dynamic (ie to store them in database) which would allow site administrators to add/change them, and again reduce all your methods to one single show method. But you would need to hit the database with that approach.

9th November, 2017

andonovn left a reply on Filtering With A Dynamic Key Problems • 1 month ago

@jgravois What's the exact error? Also, turn the Vue dev tools on (I am aware of the Chrome extension only but there might be others, too) and see if all of the data and props' values are exactly what you are expecting these to be. An alternative would be to add console.log(this.typer) as well as few more for each of the variables.

andonovn left a reply on Call To A Member Function GetUpdatedTemplate() On Null • 1 month ago

@muazzamazaz Most probably you are receiving the error on this line $template->getUpdatedTemplate($template, $request); which is part of the Save_Template() method. That's because few lines above $template = Notification_Template::find($request->id); is returning null. Most probably you didn't pass the id parameter correctly or you don't have an existing template with that id in the database.

6th November, 2017

andonovn left a reply on Testing Updates With Live Data • 1 month ago

@livijn If you are using MySQL, you have the mysqldump command which can export the db, or parts of the db. Examples to export the production db and examples to import locally. You don't have to write a script for this :) And I believe different databases (other than MySQL) would have a similar build-in feature.

5th November, 2017

andonovn left a reply on Find Results For Specified User If They Exists • 1 month ago

@nenads Then the only thing in my mind is to manually write the query. Something like this (not tested tho)

$tests = Test::leftJoin('test_user', 'test_user.test_id', '=', 'tests.id')
    ->leftJoin('users', 'test_user.user_id', '=', 'users.id')
    ->where(function ($query) {
        $query->where('users.id', '=', $user->id)
                    ->orWhereRaw('users.id IS NULL');
    });

I don't really like the @robrogers3 suggestion as there would be one hell of methods to define the same relationships for different use-cases. It's more straight-forward to have the relationships defined in one place only, and use them per your needs.

4th November, 2017

andonovn left a reply on Find Results For Specified User If They Exists • 1 month ago

@nenads Why not just $user->tests()->get() ?

3rd November, 2017

andonovn left a reply on Best Way To Sort Columns • 1 month ago

@Boubou No matter what language and/or framework you use, the best way (in most cases) to sort the data is inside your database query. In Laravel you can use Eloquent \App\User::orderBy('name', 'desc')->get();, or the query builder \DB::table('users')->orderBy('name', 'desc')->get();. To speed it up a little bit you can add an index to the name column in your users table (for this example).

andonovn left a reply on Class Not Found On Composer Dump-autoload • 1 month ago

@blasher Do you have the blasher directory inside your vendor directory? And how do you install your package? Because I can see you advised composer install --dev blasher/laratest in your readme file but I believe it should be composer require blasher/laratest

25th October, 2017

andonovn left a reply on Models For Details With Multiple Structure • 1 month ago

@martinbean All I wanted to say is that in some scenarios, it may be better to have a dedicated table for each of the 3 companies, rather than just one companies table with only 3 records inside it. That way, you can specify the exact fields each of the companies would have, and is very flexible when it comes to relationships with other tables. However, as I already said, that would make sense only if all of the project's features are related to the specific companies. And most importantly, the companies will never change (or are less likely to change ever), because the app won't scale good otherwise. But will surely make the development process much easier and cleaner comparing to having just one company table. And for the things that they have in common, you can still have a company table to contain the shared fields, and each of the three tables would have a 1-to-1 relation to that table.

And just to make one thing clear - I agree with what you suggested, that's valid for most of the use-cases. And I also shared the same thing in my initial answer. What I didn't like in your statement is the word should. Because what should someone do depends very much on the project and the requirements.

Also, thanks for getting back on the point, really appreciate that!

andonovn left a reply on Models For Details With Multiple Structure • 1 month ago

@martinbean I think you are missing the point of the forums. It's not about who is right, and it's not about showing disrespect to others by being sarcastic. Next time try to share your thoughts and try to understand the other people's point and maybe both sides will have something to take at the end of the conversation. Anyways, have a nice day

24th October, 2017

andonovn left a reply on Models For Details With Multiple Structure • 1 month ago

@martinbean why he "should"? What if the project is really all about the 3 companies and all the features in the application are exclusively working for the 3 particular companies? Making these dynamic (ie rows in a company table) would be an absolute kill for the application.

andonovn left a reply on Models For Details With Multiple Structure • 1 month ago

@simao That's a possible option but is a weird thing to do in my eyes. I don't see how the switch statement helps. It doesn't matter if you have 3 different relationships defined in separate methods, or just a single method with a switch statement. In both scenarios, you would need to be explicit about all the relations. The switch solution only relies on additional database column and make the code harder to read in my eyes. Anyways, if that works for you and makes you feel good, go with it :)

andonovn left a reply on Models For Details With Multiple Structure • 1 month ago

@simao so what? You can have dozens of defined relationships on single model. The only thing that matters is how you use the relationships.

23rd October, 2017

andonovn left a reply on App Structure For Laravel-Vue2 Multi Page App • 1 month ago

@lnb596844 I tried several things and what worked for me best is each page to have its own JS file from where I create a new Vue instance. If I need to pass data, I create a component and pass it as props (that can be avoided with additional AJAX requests tho). Usually, passing props and emitting events is enough for state management, but sometimes you may need to break the Vue component to lots of small components (to make the code more readable and speed up the app) and I find the "Bus" very useful (there is an example in the official Vue docs but basically you need another Vue instance which you can access from all your components). Vuex is kind of overkill for multi page applications. I used it in SPAs however, and I must admit it's very useful there. I am using it even for small projects (but SPA only).

andonovn left a reply on Localize After Validation Hook • 1 month ago

@akogler Replace 'Sorry, but you will need to wait as you can request one password recovery per minute.' with trans('validation.password_recovery_limit_reached'). Open lang/de/validation.php and add the password_recovery_limit_reached key to the array with a value of the german translation. Also, add the same key (password_recovery_limit_reached) in the lang/en/validation.php with the value of Sorry, but you will need to wait as you can request one password recovery per minute.. Repeat that for all the translations you need to support.

andonovn left a reply on Models For Details With Multiple Structure • 1 month ago

@simao It depends on your project. But for most use-cases you would need two models: Employee and Company. An employee belongs to company. A company has many employees. The so called "one to many" relationship. If you ask for the columns, then it very much depends on the project because there are several ways to structure them.

But as I said, it very much depends on your business requirements. If the companies you are referencing to are exactly 3 and they will never change in time, and the whole project is built around them, then you surely can have 3 models, one for each company. You can still have one Company model to contain the shared attributes, and having a 1 to 1 relationship between this model and each of the 3 company models.

There are other use-cases, too. I am just stating the two most common, that's why I said it depends :)

17th October, 2017

andonovn left a reply on One To One Relationships While Saving "historical" States? • 1 month ago

@andrixh Yeah, that sounds reasonable. At the end of the day the database design should make your life easier when executing queries against the database.

16th October, 2017

andonovn left a reply on One To One Relationships While Saving "historical" States? • 1 month ago

@andrixh Your currentDetails() implementation may look like return $this->details()->latest()->first() instead of return $this->hasOne(CustomerDetails::class)->latest()->first(). IE, define your relationships once, and use them.

The usage would be as simple as $customer->currentDetails(). Just remember this may return null so check for that before stacking with other methods/properties. Quick tip tho: if you are using Laravel 5.5, you can use the optional() helper like optional($customer->currentDetails())->someMethod() without checking for null :)

andonovn left a reply on One To One Relationships While Saving "historical" States? • 1 month ago

Your currentDetails() implementation may look like return $this->details()->latest()->first() instead of return $this->hasOne(CustomerDetails::class)->latest()->first(). IE, define your relationships once, and use them.

The usage would be as simple as $customer->currentDetails(). Just remember this may return null so check for that before stacking with other methods/properties. Quick tip tho: if you are using Laravel 5.5, you can use the optional() helper like optional($customer->currentDetails())->someMethod() without checking for null :)

andonovn left a reply on How To Query Pivot Table Where Clause? • 1 month ago

@mchiasson How about this one?

$department = Department::findOrFail($id);
$past = $department->users()
    ->wherePivot('term_end_date', '<', '2017-10-10')
    ->get(); // execute the query

andonovn left a reply on SortBy And Accented Words • 1 month ago

@Corban another option would be orderBy(\DB::raw('last_name COLLATE utf8_french_ci'));

andonovn left a reply on I Have Created A Trait That Creates A Table In The Database If It Doesn't Exist. The Table Is Created Perfectly In The DB But I Get An Error: • 1 month ago

@marcoCarcangiu Just change $this->createTranslationTable; to $this->createTranslationTable(); so you call the method instead the property.

And just to warn you that it's not a good thing to create database tables dynamically unless you really need it, which I doubt is your case. Try to use the build-in database migrations for this. If you can't by any reason, then at least avoid executing these queries when Eloquent models are created...

andonovn left a reply on Controller Question (CRUD) • 1 month ago

@archiebango If you just read the documentation, you should be able to figure out all your questions by your own. Anyways, I will assume that you really need the help and answer the questions:

Question 1: with() is used to pass a variable to your view. That variable would be called $i and would contain the number where the paginator started counting for the current page. That may sound confusing, so few examples: On page 3, the variable will equal to (3 - 1) * 5 = 10 (the items on page 3 would be from 10 to 15) On page 5, the variable will equal to (5 - 1) * 5 = 20 (the items on page 5 would be from 20 to 25) However, that variable is redundant in most cases. The paginator itself has a lot of build-in methods that should be enough. Usually, there is no need to make such calculations, so I would bet the developer who wrote the code wasn't aware of the paginator's build-in features.

Question 2: request() is a helper function that would return an instance of the Illuminate\Http\Request class. That class has a validate() method which raises an exception if some of the validation rules are not met. Then the exception handler handles that validation and automatically return a response. So the code after the validate() method would be executed only if the validation passes.

Question 3: The first line obviously takes all the request data and create an article with it. The second line is again quite obvious - redirect to a named route articles.index Here the with() method just adds the success key into the session for the next request only. Other developers may write ->withSuccess('Article created successfully'); which is again the same thing.

andonovn left a reply on SortBy And Accented Words • 1 month ago

You may try using the COLLATE keyword (at least that's for MySQL, not sure for the other DB engines).

Something like this should work: ->orderBy('last_name', 'ASC COLLATE latin1_german2_ci')

Ref: official MySQL docs

13th October, 2017

andonovn left a reply on Why Can't I Call ::has() On A Model? • 2 months ago

Do you have the comments() relationship defined in your App\Thread class?

I've just played around with it for few minutes and I received that error when accessing a non-defined relationship, so weird. All is working like a charm when the relationship is defined tho :)

andonovn left a reply on Are Laravel's Model Conventions Breaking PSR2 • 2 months ago

From what I've seen so far, the only snake_case usage is when accessing properties. And I believe that's because snake_case is the default convention accepted for MySQL columns' names. So I guess that's the reason for this decision - to keep the column names and the model properties in sync.

12th October, 2017

andonovn left a reply on After Three Login Failed Attempts I Need To Lock The User Account. • 2 months ago

@madala if you are using the build-in authentication, you can add the maxAttempts property to the App\Http\Controllers\Auth\LoginController and assign it to 3. There is a build-in throttling, but if you need to write a custom logic, you can override the sendLockoutResponse() method (again inside the LoginController) or listen for the Illuminate\Auth\Events\Lockout event.

Keep in mind that locking the user's account may not be a good idea since any user can lock any other user's account...

andonovn left a reply on Call To A Member Function Select() On Boolean • 2 months ago

Read your error again, it says it all: FatalThrowableError in Repository.php line 13: Call to a member function select() on boolean in Repository.php line 13

I bet the line 13 is $builder = $this->model->select('*');

which just means that $this->model is returning a boolean, in your case false. So basically that translates to $builder = FALSE->select('*'); which is what triggers the error. The -> syntax is to access property/method on object. Using it on boolean does nothing but triggers an error.

Most probably you have a method called setModel() or something whether inside the Repository or the MenusRepository class which you can use before calling the get() method. The quick fix of the problem is to add $this->model = new \App\Menu; before $builder = $this->model->select('*'); Just make sure the\App\Menu class extends the \Illuminate\Database\Eloquent\Model class.

And just to let you know that the code you pasted is not well structured at all and does not follow the widely accepted best practices.

5th October, 2017

andonovn left a reply on I Want Solution For This Error • 2 months ago

@hazaa90 Most probably your PHP version is old.

4th October, 2017

andonovn left a reply on How Can I Use Another Database For Login? (Laravel 5.3) • 2 months ago

It seems like you are building a multi-tenancy app. There was a good talk on that topic by Tom Schlick at Laracon US 2017 which you may want to hear.

Two tips tho:

  1. Things like setting the default database does not belong to controllers. Creating a global middleware that will execute on each request seems a much better option
  2. Do not use the env() function outside of the config files. It's really slow. And by using it from the configs, you can just cache the configs during deployment via the php artisan config:cache

26th September, 2017

andonovn left a reply on VUE Dynamic Components Loading • 2 months ago

@Spec Sure, you can. Vue supports dynamic components out of the box, take a look at the official docs and/or this article.

andonovn left a reply on VUE Dynamic Components Loading • 2 months ago

@Spec When you are using Vue, or any other frontend framework, then do NOT manipulate the DOM with jQuery.

If you don't know how to avoid the jQuery DOM manipulation (in this case the use of the append method), then post your complete use-case and we will help more.

25th September, 2017

andonovn left a reply on Trying To Do A Login Test From Browser Test • 2 months ago

@tsaicharlie93 yes, it's because the redirect didn't happen. Most probably because there was no user with the given credentials.

PS When Dusk test is failing, there would be a screenshot for you in the tests/Browser/screenshots/ directory. Sometimes that's very useful.

andonovn left a reply on How To Organize The Correct Structure For Vue + Vuex + Laravel Mix? • 2 months ago

@jarrro What make you think that you are forced to use one input file? What's the limitation you are facing? You can stick to your implementation (every page to have its own Vue instance) with or without Vuex.

A bit of off-topic to share my personal opinion: Vuex is very powerful when building SPAs, but in the world of the server rendered applications - I am not really sure if we can benefit its power. Give it a thought if you really need it before continuing with the implementation :) If it's for educational purposes - go for the SPA so you can see the power in action.

andonovn left a reply on How To Organize The Correct Structure For Vue + Vuex + Laravel Mix? • 2 months ago

What make you think that you are forced to use one input file? What's the limitation you are facing? You can stick to your implementation (every page to have its own Vue instance) with or without Vuex.

A bit of off-topic to share my personal opinion: Vuex is very powerful when building SPAs, but in the world of the server rendered applications - I am not really sure if we can benefit its power. Give it a thought if you really need it before continuing with the implementation :) If it's for educational purposes - go for the SPA so you can see the power in action.

andonovn left a reply on How To Prevent Other Users Editing Someone Else's Resources. • 2 months ago

@jakew There are several "Laravel-ways" to achieve this. The fastest one is to replace Auth::user()->books()->find($book->id)->delete(); with

abort_unless($book->user_id === Auth::user()->id, 401);

$book->delete();

That way you will save one useless database query and will improve the readability.

24th September, 2017

andonovn left a reply on How To Filter A Collection With A Many To Many Polymorphic Relationship? • 2 months ago

@ronon You may eager load the tags and then filter the results with php. It may look like this: (not tested tho)

Video::with('tags')
    ->get()
    ->filter(function (Video $video) {
        return $video->tags->isNotEmpty();
    });

Of course the better way would be to do that on database level (ie what you are already trying). To see what's are the queries Eloquent is executing, you can use \DB::enableQueryLog(); anddd(DB::getQueryLog()); respectively before and after query. I guess you will manage to get the desired result after playing around while seeing the actual queries. If not, reply again :)

23rd September, 2017

andonovn left a reply on Get Pivot Row After Attaching Many-to-many Entities • 2 months ago

@Organizm238 To be honest, something doesn't feel right to me with your application's design. But I may be wrong as I don't know the business logic. As for the same reason, I can't give any advice of what can be improved.

At least I can suggest you to use

$meetingUserId = MeetingUser::insertGetId([
    'user_id' => $user->id,
    'meeting_id' => $meeting->id,
]);

instead of

$user->meetings()->attach($meeting->id);
$meetingUser = MeetingUser::where(['user_id' => $user->id, 'meeting_id' => $meeting->id])->first();

just to save one line of code which happen to be useless database query :)

And to answer the exact initial question:

$meetingUser = MeetingUser::create([
    'user_id' => $user->id,
    'meeting_id' => $meeting->id,
]);

andonovn left a reply on Get Pivot Row After Attaching Many-to-many Entities • 2 months ago

What's the exact use-case? I mean why would you need to do that right after the insertion? Normally, you would have all the data available before the insert, so there would be no need to trigger additional db queries.

If you need to know how to access pivot data in other parts of your application, then you would need something like:

foreach ($user->meetings as $meeting) {
    $meeting->pivot->some_column_on_the_pivot_table;
}

And that to work, you would need to chain with the withPivot() method when you are defining the Eloquent relation. So in your User model you would have:

public function meetings()
{
    return $this->belongsToMany(Meeting::class)->withPivot('some_column_on_the_pivot_table');
}

18th September, 2017

andonovn left a reply on Creating Parent Child Dropdowns • 2 months ago

@crazytoon hope this will get you up and running - https://jsfiddle.net/49gptnad/520/

Just next time before asking for help, try something by your own and show your progress, share where you struggle, what are your thoughts, etc :)

Edit Your Profile
Update

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