andonovn

Experience

90,560

49 Best Reply Awards

  • Member Since 2 Years Ago
  • 605 Lessons Completed
  • 0 Favorites

15th September, 2018

andonovn left a reply on No Query Results For Model [App\Requisition]. • 1 month ago

Do you have a record in your requisitions table with an ID of 5?

If you have enabled soft deletes, make sure the deleted_at column is null for that record

1st September, 2018

andonovn left a reply on Ajax Request Throws Methodnotallowed Exception • 1 month ago

@SmokeTM Most probably your article/vote endpoint is defined with the wrong method in your routes file (can be routes.php if you are using an older version, or web.phpor api.php in the new ones). So just open it and make sure it's registered as post because from what I can see that's how you utilise it from your frontend.

By the way, a quick tip to check it faster is to run php artisan routes:list | grep vote in your terminal. That would list you all your endpoints containing vote in their urls or names, and each line will contain the associated http verb

andonovn left a reply on Company Change At Nav Level • 1 month ago

Oh, I see! I knew it may be something weird like that tho :)

You are welcome :)

31st August, 2018

andonovn left a reply on Laravel + Wordpress Connection • 1 month ago

Oh, I didn't know you can change the WP passwords hashing algorithm, that's a nice feature :) And sorry that I can't be of a help, really not familiar with that kind of packages, plugins, etc. But if you already managed to solve the problem and it's working great, then to be honest I wouldn't be looking for a package if I were you :D

andonovn left a reply on Laravel + Wordpress Connection • 1 month ago

@goncalolopes The problem I can see this way is that the user won't be able to authenticate himself/herself when using the WP login. Because you are hashing using your Laravel (bcrypt) algorithm. And WP would hash the password in a different way. Not sure if that's a problem for you, tho, because you may only need the user to appear visually in WP. But in case you want to allow WP logins, then you can simply create an endpoint in your Laravel app which will accept a user/pass and will check if you have an existing user with the provided password in your Laravel database and will return accordingly. Then you can hook into WP's build-in hook after login fail (not sure how it's called) and utilise your Laravel endpoint to decide if the provided credentials are correct, so you can manually log the user in. Of course for security reasons make sure to create a simple random long string to be used as an API token, and copy/paste it in both projects. So you can be sure that only you can access that endpoint.

andonovn left a reply on Cant Install A Working Existing Project • 1 month ago

@dabnad Maybe you are somehow overseeing the error but it clearly says what's wrong: It is unsafe to run Dusk in production.

Are you excluding your dev dependencies on your production server? What I mean is you should run composer install --no-dev instead of just composer install.

Another reason for the problem to occur is if you don't have an .env file on the server you are installing the project. In Forge you can easily control the .env file by visiting Sites (from the top nav bar) -> the site you want to install -> Environment (from the left menu) -> Edit environment

andonovn left a reply on Company Change At Nav Level • 1 month ago

@dan3460 I believe all you need is to put View::share('companies', $companies) in a service provider. Here is an example from the docs

By the way, most probably your id should be user_id. Because it doesn't really make much sense to query against the id column in the assignments for a user id. But I don't really know what you are building, so I may be wrong :)

15th August, 2018

andonovn left a reply on Modifying Dates Returned By Query • 2 months ago

@Cronix I agree that your solution is indeed the best (if there is such thing) approach to the problem. A "Laravel-ish" implementation of that would be to create a local Eloquent scope called something like scopeWithDatesInTimezone() so you can use it from the controller (and everywhere else) to make it look more nicely and human readable. Also, you can define that as a global scope if you want to apply it to all your queries. More about Eloquent scopes in the docs

@mr-gayda Just a ping so you can mark Cronix's reply as best one instead of mine. As that would help people in the future coming from Google to find the best approach faster.

14th August, 2018

andonovn left a reply on Modifying Dates Returned By Query • 2 months ago

What you are doing is perfectly fine because it simply get the job done. I personally would do the same if that's something I need to achieve fast and if it's a small application where all it's doing is inside this controller.

That being said, here are few things you can consider if you still want to improve this:

  • I guess $results, $key and $value have these names for the sake of the example. But if that's really how you named the variables, then it would be cooler to name these better. In Laravel we value such small things.
  • Many folks would use the Collection instance you have (your $results variable) and will get rid of the foreach in favour of collection method called transform. That would also get rid of the temporary variable $results as it would be redundant.
  • If that's a bigger application, a good thing would be to clean your controller from that logic. The more "Laravel-ish" way of doing this is to create a custom request instance and move the transformation logic there. Then your controller could end up looking similar to just return $request->applyTransformers(Something::select('created_at', 'value')->get());

22nd July, 2018

andonovn left a reply on Vue Like Component In Posts View • 3 months ago

Not really sure I understood the question but you can have as many instances of a component as you want to on any page.

andonovn left a reply on Customizing Laravel Built-in Auth • 3 months ago

Do you have a reason to have a separate accounts table? And, do you insist on first inserting the users' data into the accounts table?

If the answer to the both questions is "no", then you can achieve all that easily by merging all the columns into the users table, then use the build-in php artisan make:auth, and also create one middleware class to check for the is_approved flag.

Otherwise, you can just build the controllers manually which is pretty straight-forward if you ask me.

And of course another option would be to use the php artisan make:auth command, and then tweak both the RegisterController and LoginController controllers, where you can optionally override methods from the RegistersUsers and AuthenticatesUsesr traits respectively.

4th July, 2018

andonovn left a reply on Eloquent Resets Some Columns Stored As $dates To NOW() • 3 months ago

I've just solved the same problem after spending an hour of pulling my hair out. It was all on the database layer. For some weird reason beyond my understanding if a timestamp column is not null, some databases will set a default value of CURRENT_TIMESTAMP and also will update your column to CURRENT_TIMESTAMP on every update. I really find this frustrating and stupid, but I am sure there is a good reason for this that I personally don't know about. So I end up adding ->nullable() to all my timestamp columns in all my migration files. Luckily, I am not in production yet and I could actually do that, but I will have to take a look at my past projects where things may be more tricky.

@chrisgeary92 I know it's been two years now and most probably you figured this out, but I am posting this for any potential developers who may have this weird issue in the future. Because I ended up in your topic after a search in Google. And I guess I won't be the last one who will search for this issue. So hopefully I saved someone else's time :)

andonovn left a reply on How To Validate Array Input Fields? • 3 months ago

I've quickly write it directly here in the comment just for the illustration purposes. Tweak it a little bit and you will get it working. Or if you can't, let us know what's the error you can't tackle. "It's not working" is how an end user can describe the code. If you consider yourself a developer, or someone who wants to be one, try to figure out the problem and solve it. Or describe in details what have you tried so far and what makes you struggle. So others can guide you.

2nd July, 2018

andonovn left a reply on How To Validate Array Input Fields? • 3 months ago

You can use a form request class with php artisan make:request and use the withValidator() method to perform your custom validation. Which may look something like

protected function withValidator(Validator $validator) : void
{
    if (! is_array($request->name) || ! is_array($request->city) || ! is_array($request->address)) {
        return;
    }

    $validator->after(function (Validator $validator) {
        foreach ($request->name as $index => $name) {
            if (isset($name)) {
                if (! isset($request->city[$index])) {
                    $validator->errors()->add('city.' . $index, 'City is required');
                }
                if (! isset($request->address[$index])) {
                    $validator->errors()->add('address.' . $index, 'Address is required');
                }
            }
        }

        // repeat for city and address
    });
}

andonovn left a reply on How To Make That In Eloquent • 3 months ago

  1. The spec model belongsTo product. And the inverse is the product hasMany specs.

  2. Then the bizProductSpec belongsTo to both bizProduct and spec. The inverse again is bizProduct hasMany bizProductSpec, and spec hasMany bizProductSpec. Alternatively, you can threat the bizProductSpec as a Pivot, thus defining a relationship of belongsToMany between the bizProduct and Spec models. So you can end up having the following in the both models:

// BizProduct.php
public function specs()
    return $this->belongsToMany(BizProduct::class)
        ->withPivot('value');
// Spec.php
public function bizProducts()
    return $this->belongsToMany(Spec::class)
        ->withPivot('value');

Just don't forget the withPivot('value'). And in the future if you add more columns in the bizProductSpec table you will need to specify them, too.

27th June, 2018

andonovn left a reply on Adding Payment Authentication • 3 months ago

@markMngoma php artisan make:auth and you have the authentication

Then you need to create a middleware which will check if the user is subscribed and redirect to the subscription page if they are not.

For the subscription page itself you can use Laravel Cashier

For the terms and conditions you can just modify the RegisterController a bit, and of course the blade template.

The account verification at the moment you would need to build manually, but again is very straight forward. By the way, if I am not mistaken Taylor is working on this at the moment and that would be included in the php artisan make:auth in the next release of Laravel.

Hopefully all that makes sense? :)

11th June, 2018

andonovn left a reply on Problem With A Component Not Updating The DOM After Prop Has Changed • 4 months ago

I believe you need to add an unique key on line 16 of the StockAllocationsForm. So you should end up with something like <tr v-for="(allocation, index) in allocations" :key="allocation.id">.

That's a good practice in Vue to avoid problems like the one you have. The initial problem occurs for performance reasons, Vue tries to replace the DOM as little as possible and cache everything possible. Giving an unique key for each item when using v-for is how you instruct Vue which item is which when it is re-rendering the list. Hopefully that makes sense.

1st June, 2018

andonovn left a reply on Best Way To Handle Complex Form With Laravel Vs Vue • 4 months ago

@hepabolu As with almost any other thing, there is no such thing as best approach. You can tackle that either with or without javascript so it's all up to you. Having said that, here is how I would tackle this:

  1. Obviously create a route and attach a controller to handle it. Probably I would name it BookController and will use a create method to display the form. Just to stick with the default Laravel conventions. But keep in mind that's optional.
  2. In the create.blade.php file I would make use of a Vue component which will handle the form.
  3. Inside that component, I would have a property called most probablystatus which by default would be something like waiting-for-isbn. Based on that variable, I would show the ISBN field only.
  4. When the user types the ISBN (and hit the Next button?) I will hit the backend via AJAX. There I would check if I have a book with that ISBN stored, and if so will return 422. Otherwise, I will fetch from the 3rd party provider. If the fetch fails, I will return 404, otherwise 200 with the information I got.
  5. Back on the client I can just check the status code and update my status variable. And of course I will bind different things in my template to that status variable. So I can show/hide different responses to the user. For example, if the response is 200, then obviously I am displaying the rest of the fields prepopulated with what I got from the 3rd party source. If the response is 422, I am displaying an error message that we already have that book. For 404 maybe just making the ISBN input border red with hint to change it or look for typo. You got the idea.
  6. Then when the user submit the form I will have a store method inside my BookController where I will just store the book. And of course validate the user's field, alongside the ISBN again, prior to storing.

For the author "fuzzy matching" you can use Laravel Scout which is a full-text search and by default ships with Algolia. Once you have the suggestions, it's very simple to show these to the user and let him pick one (again, you will just bind the user's choice to a variable in the Vue component)

Hopefully all that makes sense? Let me know if something is not clear and I will go in more details :)

23rd May, 2018

andonovn left a reply on Selecting Laravel Version • 5 months ago

@Nagamma As with almost any other software, you should go with the latest version of the framework. That way, you will have as much as possible bugs fixed, long-term support, security updates, and most importantly cool new features.

20th May, 2018

andonovn left a reply on $app['config'] • 5 months ago

@Mahmoudy Most probably the $app variable is holding an instance of the Illuminate\Foundation\Application

When you access it as array, it will resolve from the service container. Since the 'config' is automatically bind to Illuminate\Config\Repository you receive an instance of that object.

And when you access that object as array, it will look in your config directory and will return you the values from there. So $app['config']['session'] will return the whole content of the config/session.php file. While $app['config']['session.lifetime'] will look at the same file but will return you only what you have stored under the lifetime key.

You can use php artisan tinker and play around with things like this. And you will be able to explain by yourself when you have such doubts in the future. To access the $app variable there, you can just use the app() helper. So just start by $app = app();

9th May, 2018

andonovn left a reply on Ignores My Middleware In Controller, Why? • 5 months ago

@shadrix By default, phpunit is not ignoring the middlewares, just tested this using Laravel 5.6. So it should be something on your side. What's the source of the signIn() method? Maybe for some reason it is calling $this->withoutMiddleware(); which instructs is disabling the middlewares.

Also, are you running phpunit with the filter option set to a_confirmed_auth_user_cannot_see_the_resend_page?

8th January, 2018

andonovn left a reply on User (client) Accounts & Sub Accounts? • 9 months ago

@alturic What exactly are you afraid of? If you can build the appropriate database schema, then do it. Laravel won't put any limitations on that. It will help you to query it easily if you decide to use Eloquent.

From Auth point of view, you can use the default Authentication php artisan make:auth and override what you are not okay with. And of course you are free to not use the default Auth at all, and build one from scratch for your needs.

andonovn left a reply on Multi Tenancy On SPA • 9 months ago

@brigman Just use your database? When a user changes the company, you should hit an endpoint to update that in your database. For all the other requests you just read the logged in user's selected company from the database and serve the appropriate data.

If that's all you need, you can even use Redis instead of database to speed up the reading.

20th December, 2017

andonovn left a reply on Is There Any Substitute Method In Laravel For Before() And After() Methods Of Kohana? • 10 months ago

@khurram11 Not sure what's your use-case but maybe what you are searching for is called a "Middleware" in Laravel. You can hook some things before and/or after the request. More information and usage in the docs

Maybe if you share what exactly you want to achieve, I or someone else will be able to help you more.

16th December, 2017

andonovn left a reply on Best Practice For Generate Laravel Request Validation In Rest Api App • 10 months ago

@vahidvs I don't think this is actually a problem. Having lots of Request classes is okay. If you are repeating yourself in some of them, just extract the shared code in a parent abstract class.

12th December, 2017

andonovn left a reply on Sending A Form-data Post Request With Guzzle Http • 10 months 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? • 10 months 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? • 10 months 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. • 10 months 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) • 10 months ago

@Mick79 yup, that's correct :)

25th November, 2017

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

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

andonovn left a reply on Optimize Static Page Routes And Views • 10 months 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 • 11 months 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 • 11 months 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 • 11 months 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 • 11 months 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 • 11 months 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 • 11 months 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 • 11 months 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 • 11 months 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 • 11 months ago

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

3rd November, 2017

andonovn left a reply on Best Way To Sort Columns • 11 months 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 • 11 months 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 • 11 months 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 • 11 months 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 • 11 months 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 • 11 months 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 • 11 months 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 • 11 months 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 • 11 months 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.

Edit Your Profile
Update

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