manelgavalda

manelgavalda

Member Since 1 Year Ago

Roquetes

FullStack Developer at GlobalsDD

Experience Points 155,340
Experience Level 32

4,660 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 947
Lessons
Completed
Best Reply Awards 101
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

20 May
4 days ago

manelgavalda left a reply on Issues With Sending An Email With A Pdf Attachment

Hey, then the problem must be on the way you are calling the successPayment function. Looks like you are calling it multiple times, but just calling it correctly the first time. Can you show us the code you are using to call it?

17 May
1 week ago

manelgavalda left a reply on Logout In Laravel Not Working

You need to use a css selector, so you are missing the # in front of the id value:

document.getElementById('#logout-form').submit();
29 Mar
1 month ago

manelgavalda left a reply on Resource Collection - Property [*] Does Not Exist On This Collection Instance.

Hey, i don't quite understand what you are trying to do, can you show us more code?

The problem is that $this references a collection instance, not an item inside the collection.

For example in case you want to work with the first item:

return parent::toArray([
    'name' => $this->first()->name,
    'industry' => $this->first()->industry
]);

manelgavalda left a reply on Dynamically Run Seeder File From Controller

Hey, you can create the class path before the new. So something like this should work:

    $class = "Database\Seeds\{$request->seederFile()}"; // notice the \ before the variable

    $wSeeder = new $class;

    $wSeeder->run($request->page_id, $wSorting);

manelgavalda left a reply on Trying To Get Property 'username' Of Non-object

Hey, looks like auth()->user() is returning null on the view, are you sure that you have are authenticated in the applciation?

manelgavalda left a reply on Problem Conection To Database

If it's not getting the configuration from your .env, maybe the configuration cached, try this:

php artisan config:clear
28 Mar
1 month ago

manelgavalda left a reply on Laravel 5.8 Phpunit Command Issues

Hey, I'm also using laravel 5.8 and I don't think the way of executing tests has changed.

What is the error you are having when executing vendor/bin/phpunit?

If you did composer install on a fresh laravel installation you must have phpunit on this path: vendor/phpunit/phpunit/phpunit.

27 Mar
1 month ago

manelgavalda left a reply on @if - Trying To Get Property 'id' Of Non-object

I suppose that you just need to check if po is null in order to know if $po_item has po:

<td>{{$po_item->vendor_company->name}}
   @if($po_item->po) //remove ->id
     <a href="{{route('employee.po.show', $po_item->po->id)}}"> PO No : {{$po_item->po->id}}</a> 
    @endif
</td> 

manelgavalda left a reply on Help With Courses

If you go to the main page you can see this 2 courses for new users:

The first one is PHP from 0, so I suggest you to start it first, the second one is laravel from 0, because laravel is a PHP language you will need to know the PHP basics so if you know nothing about PHP start with the first course.

manelgavalda left a reply on How Do I Filter The Eager Loading Results?

@CHRISGRIM - I think you can pass a closure to the load class and maybe this will work for you:

$category = $category->load(['events' => function ($query) {
    $query->whereNotNull('approved');
}])->get();

Does it work?

manelgavalda left a reply on How Do I Filter The Eager Loading Results?

You can use whereHas for this:

$category->load('events')->whereHas('events', function($query) {
        $query->where('approved', Null);
    })->get();

Docs: https://laravel.com/docs/5.8/eloquent-relationships#querying-relationship-existence

manelgavalda left a reply on Installing Nova 2.0 On Laravel 5.8 Is Throwing Errors

@AGILASADI - Yes, nice. Are you sure that now you are getting the same error as before?

manelgavalda left a reply on Installing Nova 2.0 On Laravel 5.8 Is Throwing Errors

@AGILASADI - Do you see the extension if you use php --ini?

manelgavalda left a reply on Installing Nova 2.0 On Laravel 5.8 Is Throwing Errors

  • moontoast/math 1.1.2 requires ext-bcmath * -> the requested PHP extension bcmath is missing from your system.

You need to install the php bcmath extension. If you are on linux you can do this:

sudo apt-get install php7.2-bcmath

manelgavalda left a reply on New Entry In Model Method

Maybe I got the question wrong, if you just want a way to create a record in the table, you can do this:

Foo::create([
    'field' = 'value',
    'field2' = 'value'
])

manelgavalda left a reply on New Entry In Model Method

Hey, yep you can use the keyword self or static to reference the own class, so this will be the same:

new self;
new static;
new Foo;
26 Mar
1 month ago

manelgavalda left a reply on Can I See The Slug Via Request?

@BEHNAMPMDG3 - You can inject the request or not, for example, In the first exemple you are injecting the request in the method, so it gets automatically resolved on your controller without looking the parameters you are passing in your route, so your route will just add the parameters that aren't injected ($slug):

public function login(Request $request, $slug)
    {
        dd($request); // the request with the data

        return view('login');
    }

If you are not injecting the request in the method you can also use the request() helper, so you don't need to import the Request class, or inject it in the controller, but the functionallity is the same:

public function login($slug)
    {
        dd(request()); // the request with the data

        return view('login');
    }

I suggest you to read the docs, you can see the same example with the request, and how method injection works: https://laravel.com/docs/5.8/controllers#dependency-injection-and-controllers

manelgavalda left a reply on Fetching User

Show us the code, what kind of problem do you have?

manelgavalda left a reply on Proper Way Of Making Migrations From Already Built Mysql Db?

I use this package, it creates the laravel migrations using an existing DB, it works pretty well: https://github.com/Xethron/migrations-generator

manelgavalda left a reply on Why Can't I See The Slug?

The request is automatically passed to the controller, you need to also pass the slug to it in order to see it:

public function login(Request $request, $slug)
    {
        dd($slug);

        return view('login');
    }
25 Mar
1 month ago

manelgavalda left a reply on Articles With Certain Categories

I guess you can use has in order to check if the relation has items:

$articles = App\Article::has('categories')->get();

Docs: https://laravel.com/docs/5.8/eloquent-relationships#querying-relationship-existence

manelgavalda left a reply on Array_merge(): Argument #1 Is Not An Array

Hey, you are not returning the variables to the view properly:

public function index()
{
    $file = new files();
    $file = $file->get()->toArray();
    return view('imgBlade.imgPage', ['file' => $file]);
}

Docs: https://laravel.com/docs/5.8/views#passing-data-to-views

manelgavalda left a reply on Diff Between {!! And {{ In Blad

Hey, the first one spaces the data for you and displays it in your html file:

  The current UNIX timestamp is {{ time() }}.

By default, Blade {{ }} statements are automatically sent through PHP's htmlspecialchars function to prevent XSS attacks. If you do not want your data to be escaped, you may use the following syntax: So it is usefull when you want to render html for example

Hello, {!! $name !!}. // $name can be "<b>Jhon</b>"

From docs: https://laravel.com/docs/5.8/blade#displaying-data

manelgavalda left a reply on Sublime Text 3 Package & Laravel Functions Helper

Hey, this is PHPStorm functionallity, in your image you can see that he is using PHPStorm in the top left corner.

24 Mar
2 months ago

manelgavalda left a reply on ErrorException (E_ERROR) Call To A Member Function DiffForHumans() On String

@BEHNAMPMDG3 - That's weird, if created_at it's not a carbon instance, you can make one of it:

{{ Carbon::parse($member->created_at)->diffForHumans() }}

manelgavalda left a reply on Can't Access Seeder File After Moving File Storage

@NHAYDER - Now you are getting a different error, the reserved word error will be something like this:

{message: "syntax error, unexpected 'Static' (T_STATIC), expecting identifier (T_STRING)",…}

And the error you are having now it's caused because php can't find the specified class:

{message: "Class 'Database\Seeds\Aaa\Anyname\TestSeeder' not found",…}

If your controller import and the seeder namespace matches make sure to run composer dump-autoload in order to solve the Class not found error.

manelgavalda left a reply on Can't Access Seeder File After Moving File Storage

@NHAYDER - Hey, you cannot use reserved words for namespacing your classes, for example you will also get an error if you use \Database\Seeds\Widgets\List\TestSeeder(). You can take a look at the reserved words list and avoid them: http://php.net/manual/en/reserved.keywords.php

manelgavalda left a reply on Can't Access Seeder File From Controller

@NHAYDER - Ah okay, thats because now the seeder has namespace so you the DB facade needs to reference the root namespace:

<?php
namespace Database\Seeds

use Illuminate\Database\Seeder;

class TestSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        \DB::table('widgets')->insert([ // Add the \ in front of DB or add use DB; on top of the file
    ...

manelgavalda left a reply on Can't Access Seeder File From Controller

@NHAYDER - What problem are you having now? Run composer dump-autoload from the terminal if it can't find the namespace

manelgavalda left a reply on Can't Access Seeder File From Controller

By default seeder files have no namespace so you can't import them, if you want to import one, you need to add the namespace to the file:

Controller

class WidgetController extends Controller
{
    public function store(Request $request)
    {

        $seeder = new \Database\Seeds\WidgetSeeder();

        $seeder->run();
        
    }

}

Seeder

<?php

namespace Database\Seeds\

use Illuminate\Database\Seeder;

class WidgetSeeder extends Seeder
{

22 Mar
2 months ago

manelgavalda left a reply on Redirect Intended Not Working Properly

Um, can you try with back() for the redirection?

    public function accept(Request $request)
    {
        $request->validate(['terms' => 'accepted']);

        return back()
            ->withCookie('terms', true);
    }

manelgavalda left a reply on API Resource Collection N+1 Performance

@PAUL-A-BYFORD - Okay, watching at this i think that you have a problem here, you are using the query builder instead of a collection:

         'latest_message' => new Message($this->conversation->messages()->latest()->first()),

When you are loading the roles, you can also load the conversation messages:

        $role->load(
            'matches',
            'matches.role',
            'matches.conversation.messages'
            'matches.person'
        );

Then I think you can try something like this:

   public function toArray($request)
    {
        return [
            'id' => $this->id,
            'role_id' => $this->role->id,
            'person' => new PersonResource($this->person),
            'status' => $this->status,
            'conversation' => $this->when($this->conversation, function(){
                return
                [
                    'id' => $this->conversation->id,
                    'match_id' => $this->conversation->match_id,
                    'latest_message' => new Message($this->conversation->messages->sortByDesc('created_at')->first()), // I use sortByDesc here just for an example
                ];
            }),
            'updated_at' => $this->updated_at->format('Y-m-d H:i:s')
        ];
    }

manelgavalda left a reply on API Resource Collection N+1 Performance

Hey, if you are already eager loading the relation, show us the code with the problem, so we can take a better look at the problem.

21 Mar
2 months ago

manelgavalda left a reply on Show Only Related Data In Search Filter

@SHAHZADSARWAR - Um I don't quite understand what you want sorry. Do you mean to display the data in the url after doing the search?

manelgavalda left a reply on Show Only Related Data In Search Filter

The first thing is that you are missing to assign the result of the where to the variable before returning it:

if ($request->has('street')) {
    $streets = $streets->where('name', 'like', '%'.$request->street.'%');
}

if ($request->has('house')) {
    $streets = $streets->whereHas('properties', function ($query) use ($request) {
        $query->where('house_number', $request->house);
    });
}

manelgavalda left a reply on Illuminate\Support\Collection::get(), 0 Passed

@SPLENDIDKEEN - If you do this, you are also getting an error?

@foreach($users as $user)
              <option>{{$user->id}}</option> 
@endforeach 


 <script type="text/javascript">

var users = {!! $users->toJson() !!};

</script>

Controller:

public function user(){
    
    $users = User::all()->keyBy('id');

    return view ('users', compact('users'));
}

manelgavalda left a reply on Method Illuminate\Validation\Validator::validateRequired|date|before Does Not Exist.

You can also use

'start_date'    => ['required|date|before:' . today()],
'end_date'      => ['date|before:start_date']

manelgavalda left a reply on Illuminate\Support\Collection::get(), 0 Passed

@SPLENDIDKEEN - The problem isn't that the user table has or doesn't has records. If the user table has records you will get a collection filled with users, and if it's empty you will get an empty collection, but it will be still a Collection so you can still call ->keyBy('id')->toJson() without a problem.

    The previous error:
    ~~~
    Call to undefined method User::keyBy()
    ~~~

    Is not related to an empty collection, it is caused because you are calling `get()` in a `User` instance not on a `Collection` instance. 
    You are doing this:
    ~~~
     var users = {!! $user->get()->keyBy('id')->toJson() !!}; // $user = User::all(); // this is a collection so it works
     var users = {!! $user->get()->keyBy('id')->toJson() !!}; // $user = User; // this is a single user (User::first(), Auth()->user()...) so you get the previous error, but it's not caused by "User::all()".
    ~~~

    So it looks like you are overwritting the $users variable somewhere in your controller or view if when it's an empty collection.

    Share the code so we can get a better idea of the problem and what to do.

manelgavalda left a reply on Illuminate\Support\Collection::get(), 0 Passed

@SPLENDIDKEEN - If I understand $users can equal to a collection or to a single model.

If that's the case maybe you can use the keyBy in your controller, so in your frontend you will call ->toJson() on your single user instance or in your collection:

var users = {!! $users->toJson() !!};

Controller:

$users = User::all()->keyBy('id');

Its a bit strange that $users can be a single instance or a collection, at least I think this should work, but you can also share the full code so we can see what makes sense in this case.

manelgavalda left a reply on Illuminate\Support\Collection::get(), 0 Passed

The problem is that $user is already a collection so you don't need to use ->get() again:

 var users = {!! $user->keyBy('id')->toJson() !!};

I also suggest you to change the variable name to $users so it will be more descriptive of what it is.

manelgavalda left a reply on Method Delete Does Not Exist.

Can you make a dd($cost_item) and see if it's an eloquent model?

20 Mar
2 months ago

manelgavalda left a reply on 419 Page Expired

@BERACAH.KINGS - Glad you solved it!

manelgavalda left a reply on How To Change User Status To Unverified Email

@KISAW88 - Is the field nullable in your migration?

$table->timestamp('email_verified_at')->nullable();

If it's still not working then check the database fields yourself (with phpmyadmin or whatever) and check that the field can be null an the default is also set to null.

manelgavalda left a reply on 419 Page Expired

@BERACAH.KINGS - Um, make sure that the route is not protected with other middlewares other than the web middleware

manelgavalda left a reply on How To Change User Status To Unverified Email

Umm, make sure that the request data is ok in order to save it, other than that I don't see anything wrong with the code, if the problem persists show us more info.

manelgavalda left a reply on How To Change User Status To Unverified Email

You are updating the email_verified_at to a string ('NULL'). Does it work if you set it to null?

$user = User::where('email',$email)->get()->first();
    $user->Type_compte=request('Type_compte');
    $user->district=request('district');
    $user->cds=request('cds');
    if($user->email!=request('email')){
    $user->email=request('email');
    $user->email_verified_at=NULL; //remoce the '
    }
    $user->password=Hash::make(request('password'));

    $user->save();
    return redirect('/comptes');

manelgavalda left a reply on 419 Page Expired

Yes, the problem is caused by the csrf_token. Because the payment gateway is an external application, you should add the route that the payment gateway needs to the $except property in VerifyCsrfToken:

class VerifyCsrfToken extends Middleware
{
    /**
     * Indicates whether the XSRF-TOKEN cookie should be set on the response.
     *
     * @var bool
     */
    protected $addHttpCookie = true;

    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        '/payment-gateway-url'
    ];
}