Nakov

Nakov

Member Since 3 Years Ago

Skopje

at SOLID Solutions

Experience Points 266,710
Experience Level 50

0 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 1545
Lessons
Completed
Best Reply Awards 189
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

17 Sep
23 hours ago

Nakov left a reply on Undefined Index

@henryoladj And I gave you 3 ideas to try out none of which is what you have shown above. So please try my 3 options one by one, exactly as I've shown..

Nakov left a reply on Passing Single Variable Across Multiple Controllers?

@sjking85 just make sure that you need the count on every view, as the simple view share will make the query for every single view, and the one I shared will make the query just on those two views that you needed it. A bit better on performance. Just making sure you understand the consequences.

Nakov left a reply on Passing Single Variable Across Multiple Controllers?

In the second action ( the index one ) you are overriding it with the users which is the model paginated.

So you either need to use different name for the parameter like usersCount for example.

Or if you want to use more advanced level you can take advantage of the View Composer

So in your AppServiceProvider boot method add this:

// import at the top
// use Illuminate\Support\Facades\View;
// use App\User;


View::composer(['dashboard', 'users.index'], function ($view) {
    $view->share('userCount', User::count());
});

Then in your view you use it as such:

{{ $userCount }}

Nakov left a reply on Validation: Class Users Does Not Exist

@sergionader and can you please show how do you validate the request? You've shown just the rules.

Nakov left a reply on Illuminate\Database\QueryException : SQLSTATE[HY000]: General Error: 1005 Can't Create Table `db_register`.`registers` (errno: 150 "Foreign Key Constraint Is Incorrectly Formed") (SQL: Alter Table `registers` Add Constraint `registers_s_id_foreign` Forei

And in your states table, is the s_id a bigInteger type or an integer?

Also make sure that the column is called s_id there, if it is just id, then change this:

$table->bigInteger('s_id')->unsigned();
$table->foreign('s_id')->references('s_id')->on('states')->onDelete('cascade');

To this:

$table->bigInteger('s_id')->unsigned();
$table->foreign('s_id')->references('id')->on('states')->onDelete('cascade');

Nakov left a reply on Facade\Ignition\Exceptions\ViewException Undefined Variable: Country (View: C:\xampp\htdocs\register\resources\views\register.blade.php)

Here is your problem:

Route::get('/', function () {
    return view('register');
});

You are loading the same view, without any data passed to it.

So use this instead:

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

Nakov left a reply on Class App\Http\Controllers\Techzadmin\Request Does Not Exist

You need to use the correct import of the class, so on top of the controller add this:

use Illuminate\Http\Request;

Nakov left a reply on Displaying Only The Data That That Particular User Input

I would use a View Composer for this case.

So in the compose method you would have something like this:

public function compose( View $view )
{
    if (auth()->user()->role === 'Staff') // make your actual check here, if you have a Gate even better.
    {
        $sales = Sales::all();
    }
    else
    {
        // for this in your User model you will have to have the relationship setup
        // this will get only the current user's sales.
        $sales = auth()->user()->sales();
    }

    $view->with('sales', $sales);
}

And you need to register it in your [email protected]:

// the first param is the view 
// don't forget the import at the top.
View::composer('sales.index', SalesComposer::class);
16 Sep
1 day ago

Nakov left a reply on Protected Fillable Not Working With Vue Axios Patch

@chrisgrim The mass assignment protection works on an Eloquent update and you are trying it on the Query Builder I believe. So try this instead:

Information::where('event_id', $event->id)->update($request->all());

But also because you are trying it on an update, make sure that the column has different value before you try to update.

Nakov left a reply on Is Mass Assignment Dangerous ?

In addition to the answer above, here is a great answer on what a mass assignment protects you from in Laravel.

https://stackoverflow.com/a/22279580/1457270

Nakov left a reply on Why My Post Is Not Deleting

You should have a delete action defined in your routes:

Route::delete('/channel/{channel}', '[email protected]')->name('channel.destroy');

Then in your view

<form action="{{ route('channel.destroy', $channel) }}" method="POST">
    @csrf
    @method('delete')
    <button type="submit" class="btn btn-danger">Delete</button>
</form>

Nakov left a reply on Undefined Index

Hmm, all looks good to me, no idea why it would throw an exception..

  • Have you tried accessing it directly from the request using request('body');.
  • Try with a different name on the element instead of body if it gets overwritten somehow in the request.
  • Try dumping the data before you use it to make sure that body exists in it using dd($data);

Couple of ideas to try out.

Nakov left a reply on How To Reload A Foreach Or View?

Really? You haven't used JS nor AJAX ever before right? You are not loading a function, you are making a request, that's what AJAX is for.

Nakov left a reply on How To Reload A Foreach Or View?

You should make an AJAX request and replace the portion of the page using JavaScript.

This is a great series for learning VueJS, but here is one video that might give you an idea.

https://laracasts.com/series/learn-vue-2-step-by-step/episodes/18

15 Sep
2 days ago

Nakov left a reply on Endpoint Link Not Showing Id

@honeybear you should learn to debug my friend. You can always try in the controller to dump whatever the result is whenever you use something.. Because obviously as I previously said the profile returns null hence the reason for trying to get id on non-object..

so try dd($user->profile) in your controller. Is your User at all a correct one?

You can use this in your controller:

public function index()
{
    $user = auth()->user();

    return view ('profiles.index', [
        'user' => $user,
        'profile' => $user->profile
    ]);
}

Because I don't know how do you link to the index action of your controller. I don't have your code. We will spent hours like this going back and forward. You will have to learn to debug.

And NO, you don't have to use $var = Class::findOrFail($var); if everything is linked as it should.

Nakov left a reply on Endpoint Link Not Showing Id

@honeybear Of course you can do it. If there was no connection between the two, then yes you would pass them as a different parameter. But when there is a relationship with it, you don't have to use different params.

Nakov left a reply on Endpoint Link Not Showing Id

But then how do you call the index action?

Why not use this instead:

public function index(User $user)
{
    return view ('profiles.index', [
        'user' => $user,
        'profile' => $user->profile
    ]);
}

Instead of passing it as a second parameter, just use the user's profile and that's it.

Nakov left a reply on Endpoint Link Not Showing Id

@honeybear my friend, the id of the profile won't show if the profile is null as you say.

I don't see how do you pass the $profile to the index page, nor how you use it. Do you load all the users, or is it just for the currently logged in one?

Make your route a named one for easier usage like this:

Route::get('/profile/{profile}/edit', '[email protected]')->name('profile.edit');

Then in your view, use it like this:

<a href="{{ route('profile.edit', auth()->user()->profile) }}"><i class="fas fa-edit"></i></a>

And as I said the profile for the current user must not be null otherwise you will get an empty place again. So you must ensure that you already have a profile for that user.. Check your database..

Nakov left a reply on Endpoint Link Not Showing Id

@honeybear there are other wrong namings in your initial post above. Is your view called index.blade.php or edit.blade.php in which you are trying to use the $profile?

You can always debug what does your profile has in your controller, just add this as a first line: dd($profile->id) if it returns null then that's why the id is empty, then there is no profile for the current user.

You can also debug in your controller if you have a profile for the current user like this: auth()->user()->profile if this returns null check the user id using dd(auth()->user()->id), and check manually in your database in the profiles table if you have a profile with that user_id. Those are couple of steps that you can take.

Nakov left a reply on Endpoint Link Not Showing Id

Why do you mix Auth::user() in your view with $user? Do you have two users? An authenticated one and the one for which the profile is being edited?

Please show how are you passing the $profile to your view in order to see if there is something wrong there?

I guess what you've shown in the controller is wrong, you should use this instead:

public function edit(Profile $profile)
{
    return view('profile.edit', [ // I assume you have an edit view under profile folder 
        'profile' => $profile
    ]);
}

Then you will be able to use $profile within your view.

The route model binding works that way. You pass {profile} to the route, it expects a parameter called $profile in the method.

Nakov left a reply on Adding New Method To Controller

@boby Thanks, this is the same as marked as solved action.

Nakov left a reply on Which Is The Best Way To Check Role Of User?

@babarkhan this is fine if you authorize based on roles, you can group multiple routes using the middleware.. if you use a policy and you check only for a role, you will have lots of duplicate code.

Nakov left a reply on Adding New Method To Controller

@boby you should mark the answer that helped as a Best Answer. Thanks!

Nakov left a reply on On Db:: Seed Error

Show the code from your AdminUser.php seeder class, not the error, as the error just shows what happened. But to get better help you must show some code that you are trying.

If I try to guess, in an array that you have in the seeder instead of , you use ;

The array items should be separated by comma, not with ;.

['name' => 'customer', 'description' => 'Custom Role'] 

So between the name and description there is a comma, and somewhere you have ; instead.

Nakov left a reply on Back And Previous Not Working As Intended

And are using ajax or just a post request?

Nakov left a reply on Adding New Method To Controller

@boby you don't need a separate specific page for an action in a controller to work, you just need to modify your form a bit, based on the Route that I've shown you above, so instead of this:

<form action="/books/{{ $book->id }}" method="POST" accept-charset="utf-8">
    @method('PATCH')

Use this:

<form action="{{ route('rent.book', $book) }}" method="POST" accept-charset="utf-8">
@csrf

Nakov left a reply on Which Is The Best Way To Check Role Of User?

Both, depends on your use case. Middleware is better to be applied to group of routes, and policies to specific actions.

Nakov left a reply on Back And Previous Not Working As Intended

You should describe the full flow, if your previuos page is / then it will return there for sure.

You can also use redirect('/intended_page') as well.

Nakov left a reply on Adding New Method To Controller

Hey Boby, I would add a new Controller called RentController and within that one a store method, that way you will follow the convention, but also logically it makes more sense, as you will know where to search for.

So your route:

Route::post('rent/{book}', '[email protected]')->name('rent.book');

Then in your controller:

public function store(Request $request, Book $book)
{
    Rent::create(
        'user_id' => $request->id(), // this is the authenticated user id
        'book_id' => $book->id
    );

    return redirect('/books');
}

You can use the route in your view with the helper method:

<form action="{{ route('rent.book', $book) }}" method="post">
@csrf

<button type="submit">Rent</button>
</form>

Something like this :) please try and let me know.

14 Sep
3 days ago

Nakov left a reply on Refactoring My Store() Method

@honeybear you should accept the answer that worked for you :) the best way to thank someone that takes time to help :)

Nakov left a reply on Refactoring My Store() Method

@honeybear you should read my answer above carefully. I said that you cannot use $request within your mutator, it should thrown an exception using $request when it does not exists.

$image is already $request->file('image'); so replace it like so:

$fileNameExtension = $image->getClientOriginalName();
$fileName = pathinfo($fileNameExtension, PATHINFO_FILENAME);
$extension = $image->getClientOriginalExtension();
$fileNameToStore = $fileName.'_'.time().'.'.$extension;
$path = $image->storeAs('public/posts_image', $fileNameToStore);

Nakov left a reply on Refactoring My Store() Method

@honeybear the mutator looks good, just don't forget to add the new value to the attributes array at the bottom of your method:

$this->attributes['image'] = $fileNameToStore;

And also you cannot use $request within the method because you are not passing it, just use the $image as that's already the file.

So your if statement will be

if($image) ...

Nakov left a reply on Class 'Intervention\Image\ImageServiceProvider' Not Found

@tigerjun you cannot manually upload a folder, the permissions won't be the same.. you need to run composer install on your server.

Nakov left a reply on Class 'Intervention\Image\ImageServiceProvider' Not Found

@tigerjun can you confirm that you have intervention\image folders under the vendor folder in your project. Because that's exactly how I use it, without the Service provider being manually registered and all seems to work good.

Nakov left a reply on Invalid Argument Supplied For Foreach() (View:

So you'll never be able to iterate over a null :D

@david2000 is it maybe this one you are testing: \Auth::user()->remarks and you don't have a method remarks in your User model?

Nakov left a reply on Invalid Argument Supplied For Foreach() (View:

@david2000 try printing out the remarks before you return the view and make sure it is a collection:

    dd($remarks);

    return view('admin.remarks.index', compact('remarks'));

Or share what instance is the object there.

Nakov left a reply on Class 'Intervention\Image\ImageServiceProvider' Not Found

I use it in one of my projects, and I have this:

"intervention/image": "^2.5",

in the composer file. Then I did not added the ImageServiceProvider in the config as I rely on the package auto-discovery, so if you use Laravel >5.5 version then I suggest you do the same.

Also try clearing the config in case it is cached:

php artisan config:clear

Nakov left a reply on Invalid Argument Supplied For Foreach() (View:

@david2000 change this line:

$remarks = Remark::orderBy('instruction', 'asc')->where('instruction','like','%'.$request->input('search').'%');

with

$remarks = Remark::orderBy('instruction', 'asc')->where('instruction','like','%'.$request->input('search').'%')->get();

Nakov left a reply on Refactoring My Store() Method

I would add a mutator attribute for the image, in which you can manage the image, and store it's path. Something like this:

// in your Post model

public function setImageAttribute( $file )
{
    if ($file)
    {
        // perform the store here
        
        // save the file path to the database field
        $this->attributes['image'] = $fileNameToStore;
    } 
}

Then you can use just this:

Post::create([
    'title' => request('title'),
    'description' => request('description'),
    'prize' => request('prize'),
    'location' => request('location'),
    'image' => request('image')
]);

Nakov left a reply on Class 'Intervention\Image\ImageServiceProvider' Not Found

@tigerjun any specific reason why you use the dev-master version of the intervention/image package and not the latest stable one 2.5.0? Try running composer update if you still got the error.

There is a StackOverflow answer regarding the same issue

https://stackoverflow.com/questions/27374613/laravel-intervention-image-class-class-not-found

13 Sep
4 days ago

Nakov left a reply on 403 Error After Validating Form

@mego the function is already there, in your ReportBug if you created it using the artisan command.

Nakov left a reply on 403 Error After Validating Form

In your custom Form request there is an authorize method which returns false by default that makes the 403. So you can return true to make it pass or use your policy there..

public function authorize()
{
    return true;
}

Nakov left a reply on Return View()->with();

Yes, because when you use with on a Response object it adds to a flash session, but when used on a view, it passes it as a parameter as I've shown you above. You can open the underlying functions in your IDE and see how they are implemented.

One is in Iluminate\Http\RedirectResponse and the other in Illuminate\View\View. Same name for the method, different implementation.

If you want to keep using the session, then add this before you return the view:

session()->flash('success', 'Action completed with 0 errors');
return view("counter", $data);

Nakov left a reply on Return View()->with();

And in the view do you have {{ $success[0] }} because you are adding an array as a value. You should do this instead:

return view("counter", $data)->with('success', 'Action completed with 0 errors');

But you should also make sure that this is the only place you return the view otherwise you will need to check if the $success is set.

@if(isset($success))
{{ $success }}
@endif

Nakov left a reply on Routing

You need to explain what you mean with that. API routes are prefixed with api btw.

Nakov left a reply on Only Get Firt Letter Passed In 2nd Nested Ajax Datatables Data Stored At Status1

@rhynel nowhere in the code I see a status1. When you use data: 'status' then your column should be called the same. So in your controller you need this:

->addColumn('status2', function ($Orders) {

// to be 
->addColumn('status', function ($Orders) {

Or please explain what you are asking a bit better, as it is not clear.

12 Sep
5 days ago

Nakov left a reply on Laravel Mail Not Using Updated .env Variables

@javillafania what value do you get then in the email? and which service are you using to send mails? Are they maybe overriding it?

Nakov left a reply on Laravel Mail Not Using Updated .env Variables

@javillafania yes, it should use it automatically. I thought you are overriding it, that's why I shared the examples above.

So what if you change the default, second parameter in the config/mail.php will it pick it up? Don't forget to clear the config cache if you are caching it.