itsfg

itsfg

Member Since 1 Year Ago

Experience Points
11,910
Total
Experience

3,090 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
107
Lessons
Completed
Best Reply Awards
1
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 3
11,910 XP
Oct
10
1 week ago
Activity icon

Replied to Create A New Primary Column In Production

@spacedog4 I also had to change a primary key in a project, and I struggled in my migration. The solution was to split the key switch into 2 Schema::table() calls, like this :

Schema::table('your_table', function (Blueprint $table) {
    $table->dropPrimary('your_primary_key_name');
});

Schema::table('your_table', function (Blueprint $table) {
    $table->increments('id');
});

It seems that operations inside one Schema::table() call are not always executed in the order you write them.

Activity icon

Started a new Conversation When Validation Fails, I Get A 422 Response But Not The Errors Property

Hello everyone,

I have a controller method that takes a custom Request class. If the validation fails, as expected, I get a 422 response with an errors property containing the errors messages defined by the validation rules :

{
    "message": "The given data was invalid.",
    "errors": {
        "product_code": [
            "The product code field is required."
        ],
    }
}

Then, inside my method, I create a second rules array, and I validate it like this :

$this->validate($request, ['affair_id' => 'required|exists:affairs,id']);

This time, if the validation fails, this is what I get back :

{
    "error": {
        "message": "The given data was invalid.",
        "status_code": 422
    }
}

The errors property is gone, I have a status_code property. And everything is nested in an error object.

Any idea why the 2 responses don't have the same format ?

This is odd, in another controller I have exactly the same system with 2 validations, and I get the errors property (first response format displayed) in both cases.

Thank you for your time

Oct
09
1 week ago
Activity icon

Replied to Need Feedback From On The Best Way To Organize Event Notifications With Pusher

Calling a controller method from another controller doesn't make much sense. Putting everything in your Event class could be the solution, if you know you calculate your event data with always the same "entry data". You can (almost) always, (almost) everywhere in your app, get your request with the Request facade. or with dependency injection.

Activity icon

Replied to Does Laravel Vapor Support Task Scheduling?

Yes it does, Taylor Otwell talks about it in the Vapor presentation : https://youtu.be/XsPeWjKAUt0?t=2838

Sep
30
2 weeks ago
Sep
27
3 weeks ago
Activity icon

Replied to Creating A File Library In Laravel

I don't see any problem to store 2 different names

(except the problem you mention, but your database won't die right ?)

(or try to slugify/sanitize/alter/modify the original name and add it to your generated name ?)

Activity icon

Replied to How To Get No. Of Users Registered For Month In 2019

@lorvent Check the method pluck() on the Collection class. When you give it 2 parameters, it's exactly what you need.

$collection_displayed_in_your_last_post->pluck('total', 'month');
Sep
23
3 weeks ago
Activity icon

Replied to How To Prevent User From Submitting More Than Once

@rr900 Yes that's it. I assume you have in your answers table :

  • a user_id, the user who is answering
  • a question_id, which question is being answered

So the 2 where() conditions limit your query to :

  • the answers of the authenticated user
  • the question actually displayed ($question)

A get() call at the end of the query gives you a collection of results.

You used all(), this is the quickest way to get all results from a table, but THAT'S IT. if you want to build a query with any condition, end it with get().

A first() call gives you back just one result, just an object. When you know your query should return only 1 row, you should use first().

Activity icon

Replied to Maximum Function Nesting Level Of '512' Reached, Aborting!

You have some sort of infinite loop going on.

In your TeamleaderCompany, do you load/append attributes that come from this TeamleaderDeal ?

If so, that's where your problem is : you load a teamleaderDeal that needs to load a teamLeaderCompany. But this company needs to load a teamleaderDeal that needs to load a teamleaderCompany ... etc ...

Activity icon

Replied to Display Date In Input Type Date Field

Hi @afoysal

Maybe it's because of the format ? You're using 'm/d/Y', try 'Y-m-d' ?

Activity icon

Replied to Best Way Do Handle Multi Option Field (with Translation)

Hi @zefex

Dealing with multiple languages is a big question and there are many possible answers.

I guess if you want to handle your multiple languages only with content from your database, you should create tables. Although, for this gender example, you will have very few possible values,.. Is it worth creating a table ?

It will depend on your whole project, will you have many translatable content or not... Also, do you need to handle all contents translations the same way or not ?

Another way could be to create an enum or string yes, storing 'man', 'woman'... And then you could create a language file with keys matching your stored values.

  • have a file translations.php (or gender.php ?) in your lang/en folder, with a line like so : 'man' => 'Man', ...
  • have a file translations.php (or gender.php ?) in your lang/es folder, with a line like so : 'man' => 'Hombre', ...

Then you call __('gender.'.$your_gender_value) to get your translated value.

Activity icon

Replied to FatalThrowableError In StaffController.php Line 83: Class 'Image' Not Found

My bad, your config file is okay. Which Laravel version do you use ? Try maybe a composer dump-autoload ?

Activity icon

Replied to FatalThrowableError In StaffController.php Line 83: Class 'Image' Not Found

First, have you installed the package intervention/image ? This is the package you're trying to use when you write "Image::"

If yes, you need to do this in your app.php (pasted from the documentation) :

1 - In the $providers array add the service providers for this package.

Intervention\Image\ImageServiceProvider::class

2 - Add the facade of this package to the $aliases array.

'Image' => Intervention\Image\Facades\Image::class

After that, your "use Image;" will work.

Activity icon

Replied to FatalThrowableError In StaffController.php Line 83: Class 'Image' Not Found

Maybe your "use Image;" is not enough ? Are you sure you have created an alias so when you call "Image" class, PHP knows which real class with its namespace it should call ?

This is intervention/image package right ?

Have you added this to your aliases : 'Image' => Intervention\Image\Facades\Image::class

Check documentation : http://image.intervention.io/getting_started/installation "Integration in Laravel" section

Activity icon

Replied to How To Prevent User From Submitting More Than Once

Hi @rr900

Maybe you could just filter your Answer query with the authenticated user id and the question id ?

$answer = Answer::where('user_id', Auth::id())->where('question_id', $question->id)->first();
//if you get null, your authenticated user didn't answer this question. If you get an Answer object, you already have an answer

In your code, the problem seems to be that you're adding every users id that have answered questions in your $matchUserIdWithAnswersUserId array.

Sep
20
4 weeks ago
Activity icon

Replied to Config Loaded From DB

Make your config accessible via a class, then bind it to a singleton via the Service Container ? This video was very useful for me to understand this subject : https://www.youtube.com/watch?v=_z9nzEUgro4

Or simpler, without using Laravel specificities, create a class with static methods :

  • One method to load all your config (coupled with a cache store like @resin said is a great idea) and store it in a static property
  • Other method(s) to get the config value(s) you need
Activity icon

Replied to Query Not Ordering By Start_date?

Do you always sort your events by start_date DESC ? If so, you could just modify the relation events and add your sorting :

public function events() {
    return $this->hasMany(Event::class)->orderBy('start_date', DESC);
}

Then your query will just be :

$events = EventUser::with('events')->where('...')->get();

If you have constraints for your events, use whereHas :

$events = EventUser:with('events')->whereHas('events', function($query) use ($compulsory) {
    $query->where('compulsory_id', $compulsory->id)->where('...');
})->where('...')->get();

This will only load events that are coherent with your where clauses.

Sep
18
1 month ago
Activity icon

Replied to How To Query This

Of course, you could also create another query in your Controller to find/count the correct answers. So you could get rid of your php calls in your blade views.

And by the way, in your blade views, instead of

<?php
...
?>

you can use

@php
...
@endphp
Activity icon

Replied to Foreach Radio Items

Waw, that's kinda hard to read.

But I think you can write something much much shorter to achieve what you need.

  • Get rid of all you "toggle-action-XX" IDs, transform them into classes like "toggle-action"
  • Same thing for you paragraphs displaying infos about the action.? Name it according to your actions, like "toggle-action-text" + a generic class that ALL paragraphs have, like "action-text"

Then with jQuery, do something like :

  • Start by hiding all your submit buttons and infos paragraphs.
  • And then in your $('input[type="radio"]').click function :
//hide all submit again
$('input[type="submit"]).hide();
//hide all your infos paragraphs again
$('.action-text').hide();
//this will work only if you have just one class on your radio. You could also use jQuery data() function to get values of attributes you create on elements. PLEASE READ BELOW ABOUT THAT
let class_name = $(this).attr('class'); 
//find closest parent form of the clicked radio, then search for a submit button in it
$(this).closest('form').find('input[type="submit"]).show(); 
//find closest parent form of the clicked radio, then search for an element having the class... in it
$(this).closest('form').find(class_name + '-text').show();

About the data function : you could place a data-action="delete" on your radio. Get the value of this attribute with $(this).data('action'). And then use this value to match the info paragraph having a class containing your action value.

Finally, why have you multiple submit buttons per form ?

Of course this is incomplete (seems you have a system of confirmation too), but it may get you on a better (at least shorter and easier to understand) way to do what you want.

Activity icon

Replied to How To Query This

Why are you using " + $key " ? Why not just " + 1 " ?

If you really get 1 or 0 back from your Model, you could even put your sum of correct answers outside of your if statement. If it is correct, you add 1, if not you add 0.

I also see you use $key for your first table cell, maybe you could change that and use the $loop variable available in blade loops. This way you can get rid of this $key completely.

Sep
13
1 month ago
Activity icon

Replied to Why Does Laravel Prepend Schema And Domain To All URLs?

That's not really easier in Laravel because you generally use the route() method, where the app domain is added to your link from one source of truth, your config file.

Also, scheme/domain being added to your URLs, you can use the same method to add links in emails you send for example.

I guess there's other reasons ? Curious to read other people answers.

Activity icon

Replied to API Integration

For your API calls, I recommend using the package guzzle (http://docs.guzzlephp.org/en/stable/), it's much simpler to use than curl directly.

PS : you can't really say that code is in PHP here. This is a JSON API, you can interact with it with curl, and PHP implements functions make curl calls.

With guzzle you will write something like this to make a GET call :

$client = new GuzzleHttp\Client();
$res = $client->request('GET', 'https://apiv2.shiprocket.in/v1/external/shipments/'.$shipment_id);
$res->getBody() //get the body of the response, this will contain the data sent back by the API
Sep
09
1 month ago
Activity icon

Replied to Log Permission Denied

We had this problem too in some applications. This was our solution :

Our webserver user is called "www", member of a group called "laravel". Composer user is also member of this "laravel" group :

## create user group
sudo groupadd laravel

## add composer user to group
sudo gpasswd -a yourlogin laravel

## add web server to group
sudo gpasswd -a www laravel

First, reset/set all permissions in your project :

## jump to laravel path
cd /path/to/your/laravel-application

## optional: if you've been playing around with permissions
## consider resetting all files and directories to the default
sudo find ./ -type d -exec chmod 755 {} \;
sudo find ./ -type f -exec chmod 644 {} \;

## give users part of the laravel group the standard RW and RWX
## permissions for the existing files and folders respectively
sudo chown -R :laravel ./storage
sudo chown -R :laravel ./bootstrap/cache
sudo find ./storage -type d -exec chmod 775 {} \;
sudo find ./bootstrap/cache -type d -exec chmod 775 {} \;
sudo find ./storage -type f -exec chmod 664 {} \;
sudo find ./bootstrap/cache -type f -exec chmod 664 {} \;

And then, this is how we declare that every new file created should have the same permissions as the parent directory :

## give the newly created files/directories the group of the parent directory 
## e.g. the laravel group
sudo find ./bootstrap/cache -type d -exec chmod g+s {} \;
sudo find ./storage -type d -exec chmod g+s {} \;

## let newly created files/directories inherit the default owner 
## permissions up to maximum permission of rwx e.g. new files get 664, 
## folders get 775
sudo setfacl -R -d -m g::rwx ./storage
sudo setfacl -R -d -m g::rwx ./bootstrap/cache

## Reboot so group file permissions refresh (required on Debian and Centos)
sudo shutdown now -r

Now, even if the root user creates the log file, it is readable/writable by the webserver user.

We now always execute this script file after a fresh laravel install.

Maybe it helps ?

Activity icon

Replied to How To Fix `laravel Recent Daily Log File Has Been Deleted`

We had this problem too in some applications. This was our solution :

Our webserver user is called "www", member of a group called "laravel". Composer user is also member of this "laravel" group :

## create user group
sudo groupadd laravel

## add composer user to group
sudo gpasswd -a yourlogin laravel

## add web server to group
sudo gpasswd -a www laravel

First, reset/set all permissions in your project :

## jump to laravel path
cd /path/to/your/laravel-application

## optional: if you've been playing around with permissions
## consider resetting all files and directories to the default
sudo find ./ -type d -exec chmod 755 {} \;
sudo find ./ -type f -exec chmod 644 {} \;

## give users part of the laravel group the standard RW and RWX
## permissions for the existing files and folders respectively
sudo chown -R :laravel ./storage
sudo chown -R :laravel ./bootstrap/cache
sudo find ./storage -type d -exec chmod 775 {} \;
sudo find ./bootstrap/cache -type d -exec chmod 775 {} \;
sudo find ./storage -type f -exec chmod 664 {} \;
sudo find ./bootstrap/cache -type f -exec chmod 664 {} \;

And then, this is how we declare that every new file created should have the same permissions as the parent directory :

## give the newly created files/directories the group of the parent directory 
## e.g. the laravel group
sudo find ./bootstrap/cache -type d -exec chmod g+s {} \;
sudo find ./storage -type d -exec chmod g+s {} \;

## let newly created files/directories inherit the default owner 
## permissions up to maximum permission of rwx e.g. new files get 664, 
## folders get 775
sudo setfacl -R -d -m g::rwx ./storage
sudo setfacl -R -d -m g::rwx ./bootstrap/cache

## Reboot so group file permissions refresh (required on Debian and Centos)
sudo shutdown now -r

Now, even if the root user creates the log file, it is readable/writable by the webserver user.

We now always execute this script file after a fresh laravel install.

Maybe it helps ?

Activity icon

Replied to Downloading PDF Files

Hi elo,

I use this package and your code seems correct, I do the same and it works. You can maybe try to add :

$pdf = PDF::loadView('receipt')->setPaper('a4', 'portrait'); //or other values you need
Aug
12
2 months ago
Activity icon

Replied to Is My Code Right For Has Or WhereHas Filter On Eloquent Relationship ?

This is correct way to use whereHas yes.

I guess it's the best way.

Unless it makes sense to create a column in your categories table to save a "last active post date" or an "active_posts_count" ? In that case, you can do what you want with just one query.