ismaile

ismaile

Member Since 1 Year Ago

Experience Points
45,380
Total
Experience

4,620 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
335
Lessons
Completed
Best Reply Awards
17
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.

Level 10
45,380 XP
Dec
02
1 week ago
Activity icon

Replied to I Have An Array Of Collections With Some Same Occurrences Like Below : ``` Array:6 [▼ 0 => Collection {#926 ▶} 1 => Collection {#926 ▶} 2 => Collection {#1045 ▶} 3 => Collection {#1045 ▶} 4 => Collection {#1156 ▶} 5 => Collection {#1156 ▶} ] `

@bobbybouwmann you are right, I think I read a bit quickly. Instead of the sum of those who repeated, I guess I have read: the sum of those without repeated. I thought the OP was looking for a way to sum without duplicates. I removed my post to avoid confusion. Assuming the collections have a unique id, @sinnbeck code looks perfect. Higher order messages for collections could also work based on the same code.

PS: Just as a little note, if it is really an array of collections, it should be converted to a collection first.

Nov
29
2 weeks ago
Activity icon

Replied to Store Morphed Model

Here is something that might be more appropriate:

web.php:

Route::post('/tasks/{task}/comments', '[email protected]');
Route::post('/customers/{customer}/comments', '[email protected]');

CommentController:

class CommentController extends Controller
{

    public function store(Model $model)
    {
        $model->comments()->create([
            'body' => request('body')
        ]);

        return back();
    }
}

PS: I used $model here to keep the explanation simple. Although it should work, I would definitely replace Model $model with an interface because we need to make sure the comments method is implemented by the model.

RouteServiceProvider:

public function boot()
    {
        parent::boot();

        Route::model('customer', \App\Customer::class);
        Route::model('task', \App\Task::class);
    }

Here we are using an explicit binding (See https://laravel.com/docs/6.x/routing#explicit-binding)

Nov
28
2 weeks ago
Activity icon

Awarded Best Reply on Custom Events And Listeners, 5.7 From Scratch Episode 32

I think I might have found the cause of your issue. You have a mail class called ProjectCreated and an event class called ProjectCreated. So, in EventServiceProvideryou might have imported the mail ProjectCreated. So , at the top of EventServiceProvider, you would only have to put:

use App\Events\ProjectCreated;

instead of:

use App\Mail\ProjectCreated;
Activity icon

Awarded Best Reply on Prevent Migrations From Being Run Automatically

If your requirement is to run 'migrate', 'db:seed' and 'queue:restart' with one command, I can think of 2 choices:

  • Putting your commands one after another in a .sh file (let's call it populate.sh):
#!/bin/bash

cd ~/path/to/myproject

php artisan migrate --force
php artisan db:seed --force
php artisan queue:restart

In this case, please make sure you specify the right ~/path/to/myproject Then, run chmod +x populate.sh to make your file executable. Then you can run it with ./populate.sh if you are in the directory where populate.sh is.

  • Create a command by running php artisan make:command MyCommand where MyCommand is the name of your command class. Then you would have to open this file, modify the signature and description (the signature value will be used when running the command as follows php artisan mysignature). Then, finally you would have to write your code in the handle method. It should be something like this based on your set of commands:
        $this->call('migrate', ['--force' => true]);
        $this->call('db:seed', ['--force' => true]);
        $this->call('queue:restart');

Hope this helps

Activity icon

Replied to Prevent Migrations From Being Run Automatically

If your requirement is to run 'migrate', 'db:seed' and 'queue:restart' with one command, I can think of 2 choices:

  • Putting your commands one after another in a .sh file (let's call it populate.sh):
#!/bin/bash

cd ~/path/to/myproject

php artisan migrate --force
php artisan db:seed --force
php artisan queue:restart

In this case, please make sure you specify the right ~/path/to/myproject Then, run chmod +x populate.sh to make your file executable. Then you can run it with ./populate.sh if you are in the directory where populate.sh is.

  • Create a command by running php artisan make:command MyCommand where MyCommand is the name of your command class. Then you would have to open this file, modify the signature and description (the signature value will be used when running the command as follows php artisan mysignature). Then, finally you would have to write your code in the handle method. It should be something like this based on your set of commands:
        $this->call('migrate', ['--force' => true]);
        $this->call('db:seed', ['--force' => true]);
        $this->call('queue:restart');

Hope this helps

Nov
27
2 weeks ago
Activity icon

Awarded Best Reply on Laravel 6 Testing Phpunit Wont Work Anymore

Do you run the following command in your terminal: ./vendor/bin/phpunit ?

Activity icon

Replied to Laravel 6 Testing Phpunit Wont Work Anymore

With the local phpunit you are pretty sure you have a correct version that could work with your project whereas the global one can have a different version.

Here is an interesting link: https://stackoverflow.com/questions/47153952/phpunit-local-vs-global-install

Activity icon

Replied to Laravel 6 Testing Phpunit Wont Work Anymore

Do you run the following command in your terminal: ./vendor/bin/phpunit ?

Activity icon

Replied to Laravel 6 Testing Phpunit Wont Work Anymore

Is there any chance that your problem could be the same as this one https://laracasts.com/discuss/channels/testing/mockery-1-illuminate-console-outputstyleaskquestion-but-no-expectations-were-specified ?

That would be unusual since it is a fresh Laravel project in your case.

Activity icon

Replied to Prevent Migrations From Being Run Automatically

Can you check if you have something related to migrate in your schedule method in App\Console\Kernel.php ?

Besides, please perform a search in all your code for something like:

call('migrate')

or

command('migrate')

These are just some ideas. These might give you a clue about where this behaviour comes from.

Activity icon

Replied to Custom Events And Listeners, 5.7 From Scratch Episode 32

I think I might have found the cause of your issue. You have a mail class called ProjectCreated and an event class called ProjectCreated. So, in EventServiceProvideryou might have imported the mail ProjectCreated. So , at the top of EventServiceProvider, you would only have to put:

use App\Events\ProjectCreated;

instead of:

use App\Mail\ProjectCreated;
Activity icon

Replied to Store Morphed Model

Indeed, my solution is more appropriate if you have a lot of other models which are "commentable" or if you might have other "commentable" models in the future. I wouldn't implement it if it is only for 2 models.

Activity icon

Replied to Store Morphed Model

@bildy I guess you are asking @tray2 but just wanted to let you know that I've just updated my code to make it a bit more practical.

Activity icon

Replied to Homestead - Accessing Via Http://localhost:PORT

Alright, here is what you could try in Homestead.yaml:

- map: localhost:8082
  to: /home/vagrant/Code/project1/public
  port: 8082
- map: localhost:8083
  to: /home/vagrant/Code/project2/public
  port: 8083

or

- map: 192.168.10.10:8082
  to: /home/vagrant/Code/project1/public
  port: 8082
- map: 192.168.10.10:8083
  to: /home/vagrant/Code/project2/public
  port: 8083

It worked for me with the second version. Of course, you should make sure you replace the to part to point to the correct project public folder. Then, please make sure you run vagrant provision

Activity icon

Replied to Store Morphed Model

What about having a common abstract controller that TaskController and CustomerController would extend. The abstract controller would implement a store method and would declare a getModel that should be implemented in TaskController and CustomerController.

To give you an idea, here are how web.php and the controllers would look like:

web.php:

Route::post('/tasks/{task}/comments', '[email protected]');
Route::post('/customers/{customer}/comments', '[email protected]');

CommentableController:

abstract class CommentableController extends Controller{

   abstract protected function getModel($id);

   public function store($modelId) {
     $this->getModel($id)->comments()->create([
            'body' => request('body')
        ]);
        return back();
   }

}

Then TaskController and CustomerController would extend CommentableController and they would need to implement a getModel method.

TaskController.php:

class TaskController extends CommentableController
{
    protected function getModel($id)
    {
        return Task::findOrFail($id);
    }
}

If you need some inspiration, in the Laravel Telescope code, you can find something pretty similar: an abstract EntryController implements an index method and declares entryType. You can check it out here: https://github.com/laravel/telescope/blob/2.0/src/Http/Controllers/EntryController.php

Hope this helps

Activity icon

Replied to Finding Mass Assignment

You can also look for $request->all() or request()->all()

Activity icon

Awarded Best Reply on Laravel Relationship Issue.

You should use a belongsToMany in this case:

public function teachers() {
    return $this->belongsToMany('App\Role')->wherePivot('name','teacher');
}

Besides, your pivot table should be called role_user instead of role_users, that's the Laravel convention: here you can find more details about it https://laravel.com/docs/6.x/eloquent-relationships#many-to-many This pivot table should have a user_id, a role_id, and a name attribute.

Activity icon

Replied to Check If Another User Is On The Same Page

This makes me think of websockets. In the Laravel ecosystem, this means Laravel Echo and the presence channel: https://laravel.com/docs/6.x/broadcasting#installing-laravel-echo

Activity icon

Replied to Laravel Relationship Issue.

You should use a belongsToMany in this case:

public function teachers() {
    return $this->belongsToMany('App\Role')->wherePivot('name','teacher');
}

Besides, your pivot table should be called role_user instead of role_users, that's the Laravel convention: here you can find more details about it https://laravel.com/docs/6.x/eloquent-relationships#many-to-many This pivot table should have a user_id, a role_id, and a name attribute.

Activity icon

Awarded Best Reply on Error In Bootstrap Files When Compiling Assets.

@memele I could reproduce the issue. Indeed as you said, it is an issue with bootstrap and precisely in the version 4.4.0. I fixed it by installing 4.3.1:

npm install [email protected] --save-dev

Assuming bootstrap is also a dev dependency in your case. Then: npm run prod would properly work.

Activity icon

Replied to Error In Bootstrap Files When Compiling Assets.

@memele I could reproduce the issue. Indeed as you said, it is an issue with bootstrap and precisely in the version 4.4.0. I fixed it by installing 4.3.1:

npm install [email protected] --save-dev

Assuming bootstrap is also a dev dependency in your case. Then: npm run prod would properly work.

Activity icon

Replied to Error In Bootstrap Files When Compiling Assets.

Are you overriding some variables in variables.scss ?

Activity icon

Awarded Best Reply on Redirect Logged User From Login Page

You need to modify the $redirectTo in RedirectIfAuthenticated

Activity icon

Replied to Redirect Logged User From Login Page

You need to modify the $redirectTo in RedirectIfAuthenticated

Activity icon

Replied to Clean Way To Save Multiple Relathionships On One Store Call

Since what you are storing is a project, I would either have the logic in the project model or in a ProjectRepository class.

However, I am surprised you have a One to Many relationship. Are you sure a project will never have more than one developer and one tester ?

Activity icon

Awarded Best Reply on Toggle Navbar Display On Page Scroll

This should work :

var lastScrollTop = 0;
$(window).scroll(function() {
    var scrollTop = $(this).scrollTop();
    if ($(this).scrollTop() != 0) {
        $('#main_header_con').hide();
        $(".main_page_nav").addClass('nav_cat_sticky');
    } else {
        $('#main_header_con').show();
    }
    lastScrollTop = scrollTop;
});

You can adjust the if condition to something like if ($(this).scrollTop() > 50) to take into account the height of the navbar.

Activity icon

Replied to Homestead - Accessing Via Http://localhost:PORT

In fact, there is no need to define different ports. To access multiple sites, you would have to set your homestead configuration accordingly and modify your hosts file to access multiple sites with a same IP address. Here is a link that might help you: https://stackoverflow.com/questions/31139284/using-vagrant-and-homestead-for-multiple-sites-and-per-project-installation

Activity icon

Replied to Toggle Navbar Display On Page Scroll

This should work :

var lastScrollTop = 0;
$(window).scroll(function() {
    var scrollTop = $(this).scrollTop();
    if ($(this).scrollTop() != 0) {
        $('#main_header_con').hide();
        $(".main_page_nav").addClass('nav_cat_sticky');
    } else {
        $('#main_header_con').show();
    }
    lastScrollTop = scrollTop;
});

You can adjust the if condition to something like if ($(this).scrollTop() > 50) to take into account the height of the navbar.

Activity icon

Replied to Opposite Of WherePivotIn

@untymage Just so you know, I have added wherePivotNotIn to the framework, so if you use Laravel 6.x and you update to Laravel 6.6 (released yesterday), you should now have access to this method in your belongsToMany relations. So, after updating Laravel, your code could be replaced with the following:

return $this->tags()->wherePivotNotIn('type',
    [1, 2]
)->exists();
Activity icon

Replied to View Error Or Bug?

So the route is not defined even when you declare it in the RouteServiceProvider whereas other routes are properly defined. Maybe, you might consider if there is any hidden character or encoding issue in your route definition. Just tossing an idea around.

Activity icon

Replied to View Error Or Bug?

Could you modify mapWebRoutes in RouteServiceProvider like the following and let us know about the outcome ?

protected function mapWebRoutes()
    {
        Route::get('users/finances/{finance}/edit', '[email protected]')->name('userfinancial.edit');

        Route::middleware('web')
             ->namespace($this->namespace)
             ->group(base_path('routes/web.php'));
    }
Activity icon

Replied to Full Calendar Previous Day Disable From Current Date.. And Also Click On Disable Days To Show My Holiday Data

What about this package https://github.com/nhn/tui.calendar ?

PS: I have not used it myself, it's the first one I came across and it looks like it is maintained and "fully" featured.

Activity icon

Replied to How To Save Image Using Array Saving Method

Post::create is used to create a new post or in other words to add a row to the database. For images, we usually store the image itself in the file system (in a dedicated directory in the server) and we store an image path in the database. So, this would be your code:

// Validating the data
$request->validate([
        'post_name'         => 'required|unique:posts',
        'post_description'  => 'required',
        'post_slug'         => 'required',
        'post_image'        => 'required|image',
    ]);
// Storing the image
$path = $request->file('post_image');
$image = $path->getClientOriginalName();
$path->move(public_path('images/post_images'), $image);
// Storing the post in the DB including the image path
Post::create([
        'post_name'         => $request->post_name,
        'post_description'  => $request->post_description,
        'post_slug'         => $request->post_slug,
        'post_image'        => 'images/post_images/'.$image,
    ]);

A little note on this code. For the post_image value, I used: 'images/post_images/'.$image because when retrieving and displaying your image, in your HTML, it would be easier to directly provide $post->post_image as a src for your img without worrying about where it is located. If you only store the image name, then you would have to specify the path in the HTML and potentially, do it multiple times if you use your image in different part of your site.

So, the code above should work. But I suggest you to read this part of the documentation regarding the storage directory. https://laravel.com/docs/6.x/filesystem#the-public-disk That's where the files should be stored.

PS: in your post, you use post_name, post_description, ..., I suggest you to rename these attributes removing the prefix post_. At some point, you are going to need to access your post data and $post->name is already explicit, so no need to call it $post->post_name

Nov
26
2 weeks ago
Activity icon

Awarded Best Reply on How To Update File Upload Laravel ?

Can you make sure you use enctype="multipart/form-data" in your HTML form ?

Activity icon

Replied to How To Update File Upload Laravel ?

Can you make sure you use enctype="multipart/form-data" in your HTML form ?

Activity icon

Replied to View Error Or Bug?

Here are various things you could try one at a time:

  • Manually delete routes.php in the folder bootstrap/cache
  • Move
Route::get('users/finances/{finance}/edit', '[email protected]')->name('userfinancial.edit');

at the top of web.php, just to check if your problem comes from any interference with other routes.

  • Make sure your model UserFinance doesn't have any getRouteKeyName defined since you use the id for route model binding.

Hope this helps.

Nov
25
2 weeks ago
Activity icon

Replied to Detach And Unlink Images

If you are using image_products, that means you are still using the Many to Many relationship. By the way, if you follow Laravel conventions, the table should be called: image_product as explained here: https://laravel.com/docs/6.x/eloquent-relationships#many-to-many

I thought you didn't want images to belong to many products.

So, one to many or many to many ?

Nov
24
2 weeks ago
Activity icon

Awarded Best Reply on [Nevermind] Can Anyone Tell Me Which Video Contains...

It seems like you are looking for Episode 12.

Activity icon

Replied to Vue Not Rendering

I have quickly scanned through the code and could not see a reference to your santa component. I was looking for something like: <santa></santa>. Is it part of your page in the section called first-section ?

Activity icon

Replied to [Nevermind] Can Anyone Tell Me Which Video Contains...

It seems like you are looking for Episode 12.

Activity icon

Awarded Best Reply on Opposite Of WherePivotIn

Something like this should work:

return $this->tags()->wherePivotIn('type',
    [1, 2],'and',true
)->exists();

Here is the API documentation showing the 2 extra parameters of the method wherePivotIn: https://laravel.com/api/6.x/Illuminate/Database/Eloquent/Relations/BelongsToMany.html#method_wherePivotIn

I set the 3rd parameter to the default value: 'and'. The 4th parameter is called $not and is set by default to false. By changing it to true, you should get the result you are looking for.

Activity icon

Replied to Opposite Of WherePivotIn

Something like this should work:

return $this->tags()->wherePivotIn('type',
    [1, 2],'and',true
)->exists();

Here is the API documentation showing the 2 extra parameters of the method wherePivotIn: https://laravel.com/api/6.x/Illuminate/Database/Eloquent/Relations/BelongsToMany.html#method_wherePivotIn

I set the 3rd parameter to the default value: 'and'. The 4th parameter is called $not and is set by default to false. By changing it to true, you should get the result you are looking for.

Activity icon

Replied to Socialite: Logging In Without Actually Redirecting To Social Site - Possible?

The first thing that comes to mind is iframes. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe

However, for security reasons, Facebook, Google or Linkedin would not allow you to have an iframe of their website except for specific use cases such as ads with Google ads (with specific source URLs). For more information, you can check this out: https://security.stackexchange.com/questions/67889/why-do-browsers-enforce-the-same-origin-security-policy-on-iframes

I don't know if it was somehow possible in the past or if some sites allow it under some conditions. But I would stick to redirection, it is secure and I think it is the standard way of doing it nowadays.

Nov
23
3 weeks ago
Activity icon

Replied to Css And Js

Let's take jQuery as an example, here is a link that might help you: https://stackoverflow.com/questions/3832446/benefits-vs-pitfalls-of-hosting-jquery-locally

Still with jQuery, one could use the CDN then the local as a fallback:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="{{asset('js/jquery.min.js')}}"><\/script>')</script>
Activity icon

Replied to SQLSTATE[HY000]: General Error: 3065 Expression #1 Of ORDER BY Clause Is Not In SELECT List, References Column 'messages.created_at' Which Is Not In SELECT List; This Is Incompatible With DISTINCT

Since you are using distinct, you should add created_at to your select, here you go:

$MsgChecker = Message::where('receiver_id', '!=', Auth::id())->where('user_id', '=', Auth::id())->select('user_id', 'receiver_id', 'conversation_token','created_at')->orderBy('created_at','asc')->distinct()->get();
Activity icon

Replied to How Can I Do A Callback On A Created Resource?

What about using Nova::serving and updating the boot method in NovaServiceProvider like this:

public function boot()
{
    parent::boot();

    Nova::serving(function () {
        User::observe(UserObserver::class);
    });
}

Source: https://nova.laravel.com/docs/2.0/resources/#resource-events

Activity icon

Replied to Route::redirect Helper Bug [SOLVED]

I've just taken a quick look at the framework code. I don't have the whole framework picture but based on your example, it makes sense to get status and destination with $parameters['status'] and $parameters['destination']. Maybe, popping the values is somehow useful although it could be unpredictable as you experienced. So, the quick and dirty fix would be to get them as you suggested and pop the values from the collection afterwards to remove them. The best would be to have other scenarios tested. Another way to fix the issue would be to replace the first line in the __invoke method with the following:

$parameters = collect($request->route()->parametersWithoutNulls());

But does it have any side effect on other scenarios ? I don't know.

EDITED

Nov
22
3 weeks ago
Activity icon

Replied to What Arhitecture Should I Develop For A Laravel + VueJS Web Application?

Assuming that you have a clear business goal and don't want to waste time, what about paying for Laravel Spark ? It can save you a lot of time and there is a section in the documentation about api driven development: https://spark.laravel.com/docs/9.0/api#api-driven-applications

As for the admin part, what about Laravel Nova ? I don't use Nova but I guess you could target the same database and get going.

I know the options I suggest are not free but if you have the budget for it, this could save you a huge amount of time and you would get a clean and maintained code. Besides, I guess a lot could be learned looking at Spark and Nova code.

Activity icon

Replied to Detach And Unlink Images

What I guess is that you apply a belongsToMany to a pivot table. Indeed, the class ImageProduct is probably the model for the pivot table.

Since you would prefer to allow products to have many images and the images are unique to the products.

That means you should go for a One to Many relationship using hasMany and wihtout a pivot table.

You would only have a products table and a table for images. Here is an example of fields for the images table:

-id
-product_id
-image_path

Here is the code for the method that should replace imageProducts:

public function images()
    {
        return $this->hasMany(Image::class);
    }

So, an Image model should be created if not already.

EDIT

Your product.blade.php would then work with:

@foreach($product->images as $image)
     <div class="owl-item" style="width: 540px;">
         <div class="item">
             <img src="{{asset($image->image_path)}}" alt="shirt">
         </div>
     </div>
@endforeach

This would be the code for deleting:

$images_path = $product->images()->pluck('image_path');
Storage::delete($images_path);
$product->images()->delete();

And finally, in the store method, you would replace:

$product->imageProducts()->sync($imagepath);

with:

$product->images()->create(['image_path' => $imagepath]);

And you would replace:

$imagepath = Storage::url('frontend/products/extras/'.$filename);

with

$imagepath = 'public/frontend/products/extras/'.$filename;

I assume you created a symbolic link at public/storage which points to the storage/app/public directory using:

php artisan storage:link

PS: I have not tested the code myself