laracoft

Member Since 2 Years Ago

Experience Points
93,840
Total
Experience

1,160 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
4
Lessons
Completed
Best Reply Awards
127
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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.

  • Community Pillar

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

Level 19
93,840 XP
May
07
1 day ago
Activity icon

Replied to How To Get Last Characters Of String

"For the end" is incorrect, should be

substr($calendar->details, -100)

$rest = substr("abcdef", -1);    // returns "f"
$rest = substr("abcdef", -2);    // returns "ef"
$rest = substr("abcdef", -3, 1); // returns "d"

https://www.php.net/manual/en/function.substr.php

Activity icon

Awarded Best Reply on Call To Undefined Method App\User::setRole()

The error log is too short, can go into storage/logs/laravel.log and extract the full thing? We need to figure out who is calling setRole().

Otherwise I suspect it may just be incompatible package versions. We can delete the whole vendor folder and composer.lock and run composer install again.

May
03
5 days ago
Activity icon

Replied to Queue:work On Cpanel

@brainyt

Step 1 in your cPanel Step 2 in your Laravel

Both steps must be performed.

Activity icon

Replied to Queue:work On Cpanel

@brainyt

  1. cPanel's Cron Jobs, run cd /path/to/your/laravel; /usr/local/bin/php artisan schedule:run > /dev/null every minute using * * * * *
  2. In your Laravel, create a scheduled task inside your ServiceProvider's boot()
// this can work on some hosting
$schedule = app(\Illuminate\Console\Scheduling\Schedule::class);
$schedule->command('queue:work --stop-when-empty')->everyMinute()->withoutOverlapping(3600);
  1. There is another way to run a daemon on some shared hosting, but needs more advanced code, see if 2 works for you first
Activity icon

Replied to Strange Sanctum Behavior When Using CURL From CLI

@mvd

No, cURL does not process the HTML portion for redirect. It is the HTTP/1.1 302 Found that causes it.

However, /api/test is supposed to output TEST, which it does when I call it using Http::.

Why does cURL get a redirect instead of TEST?

Activity icon

Replied to Mass Assignment

@davy_yg

  1. What error are you getting?
  2. What is the value of prod_main_img in your database after create()?
Activity icon

Started a new Conversation Strange Sanctum Behavior When Using CURL From CLI

Hi,

My following code works, i.e. I'm able to call the API to perform tasks:

    $token = 'sanctum|token|abcdefg';
    $response = Http::withToken($token)
        ->post('https://example.com/api/test', []);

What I can't figure out is, why curl from the CLI redirects me to /login

curl \
    --header "Authorization: Bearer sanctum|token|abcdefg" \
    https://example.com/api/test

...

> GET /api/test HTTP/1.1
> Host: example.com
> User-Agent: curl/7.61.1
> Accept: */*
> Authorization: Bearer sanctum|token|abcdefg
>
* TLSv1.3 (IN), TLS handshake, [no content] (0):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* TLSv1.3 (IN), TLS handshake, [no content] (0):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* TLSv1.3 (IN), TLS app data, [no content] (0):
< HTTP/1.1 302 Found
< Date: Mon, 03 May 2021 06:50:11 GMT
< Server: Apache
< Vary: Authorization
< X-Powered-By: PHP/7.4.13
< Cache-Control: no-cache, private
< Location: https://example.com/login
< Strict-Transport-Security: max-age=31536000
< Access-Control-Allow-Origin: *
< Set-Cookie: XSRF-TOKEN=eyJpdiI6IkFqT1BHVitlaURLZ3dYOHVxVTR2amc9PSIsInZhbHVlIjoicVpJSU52RXVzbEpRNmF5OXdXbzBrS3MxWittbW1IaHU4WE9YVW1Cd0dYK3E2ZzBOVkhRWTJ5RlBZZXMvZU9uMmxnR2NUVlJEbkdwdjhIMXk3R2VwK1oxakFPYjNxZFY2OVlNTUlPR1V3UFp5WlhWa0lhVXdzN0luMnFTOU5nYXQiLCJtYWMiOiI3OTQyYWNmY2FiZDcxYThhNWE2MWQ4YjZkZTYxZWQzZTIyYmNhMDJjMmFlYmFhNGUwNDU5ZjRjY2RiNWNhNmU4In0%3D; expires=Mon, 03-May-2021 08:50:12 GMT; Max-Age=7200; path=/; samesite=lax
< Set-Cookie: ********_session=eyJpdiI6ImJXTHlENVpzOFBleDNnbkJnZHZPNUE9PSIsInZhbHVlIjoiM0MrbXlKWVluaEJwY3p0TTRRMHNUdHVHNDZ3NTVLRUlCZnAwQnBqeGwrZUgwUGFOSytYUUVtMEd0N2lveDh5SExZQ2ZRZDRRZk51ME1pdW0xejJWejI1bDdJQm9wTklMSnl1R08xU3lNNGhiWXh6WnpvOW9FWE8wMUNGMDlsRkgiLCJtYWMiOiJiMDY5MDI4ZTdiODBkYjM5MTFiMDIxMTRmZmM2M2VhOWZhMGUzMTJkMmI4YjYwMWRmM2NlOTE4N2IwYzI4MDc4In0%3D; expires=Mon, 03-May-2021 08:50:12 GMT; Max-Age=7200; path=/; httponly; samesite=lax
< Content-Length: 386
< Content-Type: text/html; charset=UTF-8
<
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="refresh" content="0;url='https://example.com/login'" />

        <title>Redirecting to https://example.com/login</title>
    </head>
    <body>
        Redirecting to <a href="https://example.com/login">https://example.com/login</a>.
    </body>

Any idea? Thank you.

May
01
1 week ago
Activity icon

Replied to What Kind Of Class Should This Be?

@fylzero

I think my aim is to store complex objects in the database using a fluent styled code with context.

In this example, I'm just starting with a receipt.

I think the code reads well as English except for some issues, such as you mentioned, some of the method names conflict with QueryBuilder, including its class name, which conflicts with the Model.

  1. As these method names give context to receipts, I would like to retain them if possible.
  2. Also, some of these methods could translate to setting multiple fields in the table(s) which can be quite a pain to do in create([...])
  3. I could rename from to issuedBy, but I could run out of options, then what do I do?
  4. So what I had in mind initially was to create another class, which led to my OP.
  5. Have you encountered such situations before? And if yes, how did you solve it?
  6. I also need issuedBy and paidWith to accept variables, so fromMcDonalds() and paidWithCash() probably won't do.
  7. Of course, the last option is to constraint my names to work with QueryBuilder

As it is a problem I'm still thinking about, this is more or less the best I can explain it. Thanks.

Activity icon

Started a new Conversation What Kind Of Class Should This Be?

Suppose I have code like below, after save() it persists to the database.

Receipt::from('mcdonalds')
    ->for('dinner')
    ->dated(Carbon::parse('2021-04-03'))
    ->paidWith('cash')
    ->taxPercent(17)
    ->taxInclusive()
    ->save();
  1. Should these methods go onto the Model? My concern is that it could clutter up the Model.
  2. Use a trait? Some methods might be just for this specific class and no other.
  3. Use another class? How should I name it etc? Receipt without an s is meant for Models.

Thank you.

Apr
28
1 week ago
Activity icon

Awarded Best Reply on Using Day Number To Get The Next Date

@cservices

    public function nextDate()
    {
        $lastDate = Carbon::now();
        $lastDate = Carbon::parse('2021-04-21 00:00:00');

        $eventDays = [3, 6];	// we only want wed and sat
        $lastDay = $lastDate->dayOfWeek;
        foreach ($eventDays as $eventDay) {
            if ($lastDay < $eventDay) { 
                break; // found our next $eventDay
            }
        }
        $nextDate = $lastDate->next($eventDay);

        dd($nextDate);  // date of next wed or sat
    }
Apr
27
1 week ago
Activity icon

Awarded Best Reply on Disable Artisan Commands

@wakanda

// register in your ServiceProvider's boot()
\Event::listen(
    \Illuminate\Console\Events\CommandStarting::class,
    \Your\Namespace\PreCommand::class
);
namespace Your\Namespace;

use Illuminate\Console\Command;
use Illuminate\Console\Events\CommandStarting;

class PreCommand extends Command
{
    /**
     * Handle the event.
     *
     * @param  object  $event
     * @return void
     */
    public function handle(CommandStarting $event): void
    {
        if (app()->environment(['production'])) {
            if ($event->command == 'migrate:fresh') {
                $this->output = $event->output;
                $this->info('Nope. Not running.');
                die();
            }
        }
    }
}
Activity icon

Replied to Disable Artisan Commands

2nd is a command file, just put it anywhere as long as namespace mtaches your folder.

Activity icon

Replied to Disable Artisan Commands

@wakanda problem solved?

Activity icon

Replied to New Laravel 8 Application Database Not Working

@zct

In your .env, does the specified DB_USERNAME and DB_PASSWORD has READ and WRITE privileges to the database?

Try GRANT ALL PRIVILEGES ON *.* TO 'your_database_username'@'%';

https://chartio.com/resources/tutorials/how-to-grant-all-privileges-on-a-database-in-mysql/

Activity icon

Replied to Disable Artisan Commands

@wakanda

// register in your ServiceProvider's boot()
\Event::listen(
    \Illuminate\Console\Events\CommandStarting::class,
    \Your\Namespace\PreCommand::class
);
namespace Your\Namespace;

use Illuminate\Console\Command;
use Illuminate\Console\Events\CommandStarting;

class PreCommand extends Command
{
    /**
     * Handle the event.
     *
     * @param  object  $event
     * @return void
     */
    public function handle(CommandStarting $event): void
    {
        if (app()->environment(['production'])) {
            if ($event->command == 'migrate:fresh') {
                $this->output = $event->output;
                $this->info('Nope. Not running.');
                die();
            }
        }
    }
}
Activity icon

Replied to Laravel And Wordpress

@eliekhazzaka

This might help https://github.com/avexsoft/laravel-sidepress and it's not much pain, well, at least not for the human. :)

Activity icon

Replied to Configure Laravel To Use Mail()

@fylzero yea, I learnt that mail() can lead to spam while googling too. Thanks!

Activity icon

Replied to Configure Laravel To Use Mail()

@fylzero

Yes, it is my intent to use only Laravel's mail and nothing else. However Laravel's Mail (Swift Mailer) basically boils down to exec('sendmail', ... under the hood.

On my shared hosting, mail() works, exec() works, but exec('sendmail', ... does not. I'm not going to argue with them.

I was also reluctant to use SMTP locally as it involves account creation/password management etc, but in the end that was what I went with.

And I'm not about to write code. #lowcode :)

Thanks.

Apr
26
1 week ago
Activity icon

Replied to Laravel Cron Directadmin

Glad it is solved. :)

Activity icon

Replied to Laravel Cron Directadmin

better talk to your host

Activity icon

Replied to Laravel Cron Directadmin

Change your cron to

cd /home/xx/domains/xx.com/xx/; /usr/local/bin/php artisan schedule:run >>/dev/null 2>&1

You must cd to the folder that has .env

Activity icon

Replied to Preg Match Output Not Correct

What are the strings you are trying to match?

Activity icon

Replied to Consuming API Directly Or Saving Into Db First

@prido

Better to save to DB first.

  1. If you pull direct from API when frontend reloads, you will easily hit the limit of the API (Assuming there is a rate limit)
  2. Frontend can also be slow if your API is slow, resulting in poor user experience
Activity icon

Replied to Issue With Ajax Post When Changing The Query String

Glad to hear that. Do pick an answer that helped you best. :)

Activity icon

Replied to Issue With Ajax Post When Changing The Query String

  1. Load your form in Chrome
  2. Open Developer Tools (Ctrl+F12)
  3. Click on the Network tab, then XHR sub tab
  4. Click on Clear, which is a No Entry icon
  5. Go back to your form, click on Submit
  6. Go back to Developer Tools
  7. Which is the URL that AJAX failed?

If you fail to identify the URL, please indicate clearly which step above you could not follow.

Activity icon

Replied to Issue With Ajax Post When Changing The Query String

Also change url:"./processuseredits", to url:"/processuseredits",

Activity icon

Replied to Issue With Ajax Post When Changing The Query String

In that case, can you use the Chrome Developer tools to identify which is the offending URL that caused the not supported exception?

Otherwise you have to show the HTML code for #edituser

Activity icon

Replied to Laravel Mail::send() How Many Free Email I Can Send From This?

@zahidgopang

It depends on where you send it through.

Under the hood, Mail::send is using SwiftMailer, which can send via sendmail, SMTP or providers like Mailgun etc. So, which provider did you configure in your .env?

https://laravel.com/docs/8.x/mail#introduction

Activity icon

Replied to Issue With Ajax Post When Changing The Query String

@wontonesaju

Show your full AJAX/HTML form code.

Activity icon

Replied to The Payload Is Invalid. Problem With Decastro4 Package Gmail API

...

  1. What is inside your gmail-json.json file?
  2. Where did you get gmail-json.json in the first place?
Activity icon

Replied to The Payload Is Invalid. Problem With Decastro4 Package Gmail API

Your token already in the JSON file. Download your token again from Google. It might be corrupted.

Activity icon

Replied to Eloquent How To Set A Specific Record At The Top(first Line)

@user1980

It's odd you want to do this... but well

...
->orderBy(DB::raw('field(id, 12) desc'))
->get();
Activity icon

Replied to The Payload Is Invalid. Problem With Decastro4 Package Gmail API

Ok, what do you think is the problem then?

Activity icon

Replied to The Payload Is Invalid. Problem With Decastro4 Package Gmail API

Add your credentials in your .env file

GOOGLE_PROJECT_ID=...
GOOGLE_CLIENT_ID=...
GOOGLE_CLIENT_SECRET=...
Activity icon

Replied to The Payload Is Invalid. Problem With Decastro4 Package Gmail API

You already specified GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET, I think just set GOOGLE_ALLOW_JSON_ENCRYPT=false.

When you say nothing happened, it might be due to other issues.

Please also remove your ID and SECRET from this post. Security issue for you.

Activity icon

Replied to Call To Undefined Method App\User::setRole()

Happy to hear that. Please mark it as the best answer. Thank you.

Activity icon

Replied to The Payload Is Invalid. Problem With Decastro4 Package Gmail API

@redataha

Is gmail-json.json supposed to be in storage/app/gmail/tokens? Or beside .env?

Activity icon

Replied to Call To Undefined Method App\User::setRole()

To remove tcg, run composer remove tcg/voyager, you cannot just delete it from the vendor folder

Activity icon

Replied to Call To Undefined Method App\User::setRole()

The error log is too short, can go into storage/logs/laravel.log and extract the full thing? We need to figure out who is calling setRole().

Otherwise I suspect it may just be incompatible package versions. We can delete the whole vendor folder and composer.lock and run composer install again.

Activity icon

Replied to Call To Undefined Method App\User::setRole()

Did you just change to setRole() to assignRole()? If yes, I think your error might be solved. Otherwise please show your full logs, and format them properly by wrapping between 3 backticks like below

```

full error logs

```

Activity icon

Replied to Call To Undefined Method App\User::setRole()

Can't confirm who is calling setRole(), but change it to assignRole(), else show full contents of CreateAdminUserSeeder.php

Activity icon

Started a new Conversation Configure Laravel To Use Mail()

Is there a way to setup config/mail.php to use PHP's mail() function?

Activity icon

Replied to Call To Undefined Method App\User::setRole()

Is your namespace correct? Shouldn't it be App\Models\User::?

Did you publish and migrate? If yes, show your fullUser.php

https://spatie.be/docs/laravel-permission/v4/installation-laravel

Activity icon

Awarded Best Reply on How To Force User Logout Via Middleware ?

It easier to solve bugs once they become black and white. :)

Activity icon

Replied to Call To Undefined Method App\User::setRole()

Which additional packages are you using?

Activity icon

Replied to How To Force User Logout Via Middleware ?

It easier to solve bugs once they become black and white. :)

Activity icon

Replied to Call To Undefined Method App\User::setRole()

Where did you come up with setRole()? The error says it does not exist.

Activity icon

Replied to How To Force User Logout Via Middleware ?

and what's the exact error?

Activity icon

Replied to How To Force User Logout Via Middleware ?

@vincent15000

Which line is the error pointing to? Please show full logs.