manelgavalda

manelgavalda

Member Since 1 Year Ago

Roquetes

Experience Points 166,060
Experience Level 34

3,940 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 1003
Lessons
Completed
Best Reply Awards 110
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.

22 Jun
3 weeks ago

manelgavalda left a reply on Append An Attribute To Collection Without Causing N+1 Issue

@THEBIGK - I think you need to load the relation with the events:

public function index()
{
    $events = Event::with('attendees')->where('start_date', '>', now())->paginate(30);

    return $events; // Testing
}

And maybe in your User model you will need to work with collections instead of the query builder:

    public function getAttendingAttribute()
    {
        return $this->attendees->where('user_id', '=', auth()->id()); // remove the () in attendees
    }
21 Jun
3 weeks ago

manelgavalda left a reply on Laravel Relations

If the user can only have 1 role I don't think you need the user_roles table.

You can simply add a role_id column in your users table.

manelgavalda left a reply on Empty Session(s) After (external) Redirect?

When the user gets redirected from the external server to your laravel server, you will have a new session, so before your laravel server redirects to the external server, you need "to pass" the session you had to the external server, and when the external server redirects you back to the laravel server you will have the session.

Finally, if you are redirecting to your laravel application from an external server, you should disable the csrf token validation: https://laravel.com/docs/5.8/csrf#csrf-excluding-uris

Hope this helps.

20 Jun
3 weeks ago

manelgavalda left a reply on Body Data Is Including The HTML When It's Input To My PhpMyAdmin...

@FORTEIRP - Mm, if you are already displaying the data using {!! $post->body_html !!} it's weird that you still see the <p> tags, if the data is correctly saved in your database I don't understand what's wrong.

manelgavalda left a reply on Package Dependencies During Development

Hey, I tend to use franzliedke/studio, is pretty easy to use, you can see how it works here: https://github.com/franzliedke/studio

manelgavalda left a reply on Body Data Is Including The HTML When It's Input To My PhpMyAdmin...

Hey, {!! !!} will show the html text unescaped so it will be rendered properly, but what you are showing in the screenshot and your code doesn't look the same thing.

In your create view you are using a class to create the textarea, so you don't need to use {!! !!} in order to scape it.

You probably want to show the unescaped text in your show view.

19 Jun
3 weeks ago

manelgavalda left a reply on Argument 2 Passed To Maatwebsite\Excel\Excel::download() Must Be Of The Type String, Object Given, Called In D:\xampp\htdocs\laravel\webpro3\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php On Line 237

Looks like you are using an old syntax. As the second parameter it expects the name of the downloaded file:

class UsersController extends Controller 
{
    public function export() 
    {
        return Excel::download(new UsersExport, 'users.xlsx');
    }
}

I don't know for sure how the others options must be implemented with the newest version, but you can take a look at the docs: https://docs.laravel-excel.com/3.1/exports/

manelgavalda left a reply on Laravel Request User

Hey, yep this is normal behavior.

When you use $request->user() you are getting an instance of User, so when you do $request->user()->first() you will get the first User.

This is not dangerous because if you are returning the $request->user() the user has no way of using ->first() after it.

17 Jun
4 weeks ago

manelgavalda left a reply on Validation: String IS NOT

Hey, I think you can use the not_in validation rule: https://laravel.com/docs/5.8/validation#rule-not-in

14 Jun
1 month ago

manelgavalda left a reply on Model Function Within FormRequest

@MIHIRPATEL83 - Um, are you sure that you are hitting the Validator, in your controller, before creating the product?

Btw if you already have a custom request class to to do the validation, I think it will be just better to have the rules in your request class.

manelgavalda left a reply on Model Function Within FormRequest

You can access the bound model frmo the url using:

        $model = $this->route('model');

manelgavalda left a reply on How To Convert My Json View In Laravel?

@RAVIAWASTI - Um, the easier thing will be for your android developer to access the first item of the array, or create a loop to show errors. If he doesn't know how to do something like:

    if ($validator->fails())
    {
        $errors = $validator->errors();

        if(array_key_exists('username', $errors)) {
            $errors['username'] = $errors['username'][0];  // Here you are getting the first item of the array and assigning it directly to "username" so it will be a string
        }

        if(array_key_exists('email', $errors) {
            $errors['email'] = $errors['email'][0]; //same as before.
        }

        return response()->json(['success'=>'0','post'=> $errors]);
    }

As I said that's a very ugly flx, but I suppose that something like this should work. Maybe somebody else can help you with your problem...

manelgavalda left a reply on How To Convert My Json View In Laravel?

Hey, can you show us why do you want to do this? The reason why the username and email fields are returning and array, is because they can have more than 1 error, so I don't think it's a good practice to pass the array into a string. What you can do in your blade is to access the first item on the array, so you will get the result you expect. If you have this:

{ "success": "0", "post": { "username": "The username has already been taken", "email": "The email has already been taken." } }

You can access the key accessing the first item on the array, so instead of accessing username to get the error, you will have to access username[0], and the same with the email.

manelgavalda left a reply on It Is That Possible To Gerate A New Class With A Custom Artisan Command ?

Yeah , instead of defining the $class_template inside the command, you can create a stub with the customClass code and generate the class using that.

I think that's a good example of what you want to do: https://medium.com/@imfx/create-make-custom-commands-in-laravel-9fa002da582e

manelgavalda left a reply on Which Type Of Format Is This In Laravel Api?

@RAVIAWASTI - They are surrended with curly braces {, so they are both JSON objects https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON.

A JSON object can have nested JSON objects inside, that's why you have more {} inside.

And in the first case this JSON object has 2 arrays of 1 item inside:

[ "The username has already been taken." ] // First array
[ "The email has already been taken." ] // Second array

manelgavalda left a reply on Which Type Of Format Is This In Laravel Api?

This format is called JSON, it's the most common format when working with apis. If you want to see the data structured, you can use https://jsoneditoronline.org/ for example.

13 Jun
1 month ago

manelgavalda left a reply on How To Remove Port In Laravel Aap In Localhost In Ubuntu 16.04

Hey, I'm not sure if I quite understand the question but I suppose, that instead of your app url being localhost:8080 you want something like your-app.test?

If that's the case you can use valet: https://cpriego.github.io/valet-linux/

manelgavalda left a reply on Phpunit Returns Green On Null

Hey, this is not failing because $thread->slug is returning null, so your string looks like "/thread/1/" and your path() function doesn't even need to return the slug.

I think a better test for this would be something like:

public function a_thread_has_a_path()
{
    
    $thread = factory(Thread::class)->create([
        'slug' => 'your-slug'   // or fill the title column and get the slug from that, so you will know that the slug is generated correctly
    ]);

    $this->assertEquals('/thread/1/your-slug", $thread->path());
}

This way you will assure that the url you are comparing is the expected.

12 Jun
1 month ago

manelgavalda left a reply on Undefined Variable

You are having this error on your controller or in your blade? The code seems right so this may be a problem with cache or compilation. Try to run this commands:

php artisan cache:clear

composer du

manelgavalda left a reply on Declare Middleware Use In Route File Or Controller

Hey, there's not any convention on this, it's just a matter of your personal preference.

Personally i like to put the middleware on the route definition, so when i take a look at my routes file I can easly see which routes are protected by a middleware and I also like to wrap all the routes in a middleware group.

Referencing from the docs https://laravel.com/docs/5.8/controllers#controller-middleware :

Middleware may be assigned to the controller's routes in your route files:

Route::get('profile', '[email protected]')->middleware('auth');

However, it is more convenient to specify middleware within your controller's constructor. Using the middleware method from your controller's constructor, you may easily assign middleware to the controller's action. You may even restrict the middleware to only certain methods on the controller class:

class UserController extends Controller
{
    /**
     * Instantiate a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');

        $this->middleware('log')->only('index');

        $this->middleware('subscribed')->except('store');
    }
}

Controllers also allow you to register middleware using a Closure. This provides a convenient way to define a middleware for a single controller without defining an entire middleware class:

$this->middleware(function ($request, $next) {
    // ...

    return $next($request);
});

manelgavalda left a reply on Error While Installtion Laravel

Hey, this is actually another problem:

  • PDOException::("SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)"

The php-mysql driver is installed correctly, the problem now is that the credentials to connect to your mysql database are not correct.

Check out that your .env file is configured properly with your mysql credentials:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE="your-database"
DB_USERNAME="your-user"
DB_PASSWORD="your-password"

manelgavalda left a reply on Error While Installtion Laravel

@INDERSEIN - - Illuminate\Database\QueryException : could not find driver.

You are missing the mysql database driver now:

sudo apt-get install php7.2-mysql

manelgavalda left a reply on RelationShip

@AFOYSAL - Hey, glad it worked, but it was @wobbie who provided the correct solution to your answer, so you can mark his answer as best, thanks.

manelgavalda left a reply on Error While Installtion Laravel

Problem 1 - phpunit/phpunit 7.5.x-dev requires ext-dom * -> the requested PHP extension dom is missing from your system.

You are missing the php xml-extension:

sudo apt-get install php7.2-xml

manelgavalda left a reply on RelationShip

@AFOYSAL - Here you are referencing the name of this relationship:

public function course()
{
    return $this->belongsTo(Course::class);
}

So you need to use the name of the relationship course, because a Semester belongs to one Course.

manelgavalda left a reply on RelationShip

@AFOYSAL - The relationship name to retrieve the course of the semester is course, not courses:

public function index(Request $request, $domain) 
{ 
    $semesters = Semester::with('course')->get(); 
    return response()->json(["semesters" => $semesters, "status"=>200]); 
}

11 Jun
1 month ago

manelgavalda left a reply on Unexpected AuthenticationException

If you want to check the redirect you need to have the exceptions enabled, so laravel can catch it and redirect you with a 302 response.

/** @test */
public function guests_cannot_manage_projects()
{
    $project = factory('App\Project')->create();

    $this->get('/projects')
        ->assertRedirect('login');
        
    ...
        
}
20 May
1 month 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 month 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
3 months 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
3 months 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
3 months 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
3 months 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
3 months 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