Ricardo

at Self employée - Two SaaS

Experience

87,380

39 Best Reply Awards

  • Member Since 3 Years Ago
  • 915 Lessons Completed
  • 1 Favorite

14th October, 2017

Ricardo left a reply on How To Get Answers To The Questions ? • 1 month ago

Damn it! my 30 years of experience thrown to trash, I don't know what are turbolinks? (Sarcastic in case any Sheldon Cooper over here)

21st August, 2017

Ricardo left a reply on Storing Calculation Formula In Database? • 3 months ago

@shawnyv take a look at PHP eval function.

18th August, 2017

Ricardo left a reply on Laravel-mix Http / Https • 3 months ago

@junik91 is totally necessary for you to separate versioning local from production?

if you tinker the mix function you'll notice a relative path:

$app = mix('/build/js/app.js');
$app->toHtml();

returns /build/js/app.js

13th August, 2017

Ricardo left a reply on Your Experience Of Bug Tracking Tools • 3 months ago

@Mithridates when a exception is thrown you get the stack trace, the request the session vars, etc. give it a try.

12th August, 2017

Ricardo left a reply on Laravel 5.2 WhereHas Column Is Ambiguous • 3 months ago

@dengdeng

$commentIds = [
    ....
    ...
    ...
];

$users = User::whereHas('comments', function($query) use ($commentIds) {

    $query->whereIn('comments.id', $commentIds);

});
`
``

Ricardo left a reply on Retrieving: Posts, Comments, Reports And The Users Who Made Those Reports For A Moderation Queue • 3 months ago

@Corbin

$posts = Post::whereHas('reports')->with('reports.users', 'comments')->latest()->get();

Ricardo left a reply on CLI Application With Laravel • 3 months ago

@rmoiseev take a look at How to Build Command-Line Apps to see if it helps.

8th August, 2017

Ricardo left a reply on Errors Occur While Sending Email With Mailables • 3 months ago

@mrnaveed any time. Would you mind marking this thread best answer, that way one can avoid entering to see if there is more todo here. Thank you.

2nd August, 2017

Ricardo left a reply on Artisan Scheduler Command, Sending Output To Terminal • 3 months ago

@trogne yes, when running from a cron job the stdout and stderr output goes no where, that's why Laravel has sendOutputTo and appendOutputTo.

Ricardo left a reply on Artisan Scheduler Command, Sending Output To Terminal • 3 months ago

@Snapey but that info goes where when >> /dev/null 2>&1?

Ricardo left a reply on Errors Occur While Sending Email With Mailables • 3 months ago

@mrnaveed the SMTP server you are sending mail from, it needs your credentials in order to allows you to send email through it

Ricardo left a reply on Artisan Scheduler Command, Sending Output To Terminal • 3 months ago

@trogne

In your crontab, this line sends the output stdout and errors stderr to the 'hyperspace'

artisan schedule:run >> /dev/null 2>&1

and is because the cron jobs are run even if there is no terminal open.

If you run it from the terminal

artisan schedule:run

It'll send the output to the terminal

1st August, 2017

Ricardo left a reply on Fire Model Event Manually • 3 months ago

@lars6 I just created:

<?php

namespace App\Observers;

use App\User;

class UserObserver
{
    public function creating(User $user)
    {
        dump($user);
    }

}

and in the boot method of AppServiceProvider I've added User::observe(UserObserver::class); then tinker:

$u = App\User::find(1);
event('eloquent.creating: App\User', $u);

And it worked

31st July, 2017

Ricardo left a reply on Fire Model Event Manually • 3 months ago

@lars6 I've added a static::creating on a User model:

static::creating(function ($user) {
    dump($user);
});

then tinker event('eloquent.creating: App\User', $u) and it dumped it.

Note: there is an space before the class name.

30th July, 2017

Ricardo left a reply on Fire Model Event Manually • 3 months ago

@lars6 I think that fireModelEventuses "eloquent.{$event}: ".static::classwhere static::classrefers to your controller not to the model.

Ricardo left a reply on Default Auth Routes In Route Group • 3 months ago

@CodebyRay I only use:

Auth::routes();

24th July, 2017

Ricardo left a reply on Need Help! Class 'Post' Not Found In Web.php • 3 months ago

@Darkcoder as @Snapey says:

Route::get('/find', function(){ 
    $result = App\Post::all();
});

Ricardo left a reply on Understand Relations • 3 months ago

@tk90

$page = Page::with('posts')->whereSlug($slug)->first();
return view('pages.show', compact('page'));

then:

{{ $page->title }}
{{ $page->text }}

@foreach($page->posts as $post)
    {{ $post->text }}
@endforeach

Ricardo left a reply on Understand Relations • 3 months ago

@tk90

@foreach($pages as $page)
    @foreach($page->posts as $post)
        {{$posts->title }}
        {{$posts->text }}
    @endforeach
@endforeach

Taking @mikevrind in account which is right:

$page = Page::with('posts')->whereSlug($slug)->first();
return view('pages.show', compact('page'));

then

@foreach($page->posts as $post }}
    {{$post->text }}
@endforeach 

Ricardo left a reply on Understand Relations • 3 months ago

@tk90 uhmm... se here

Ricardo left a reply on Understand Relations • 3 months ago

@tk90

Page::with('posts')->whereSlug($slug)->get()

then

@foreach($pages as $page)
    {{$page->post->title }}
    {{$page->post->text }}
@endforeach 

Ricardo left a reply on Paginate • 3 months ago

@mattnewark

$tickets = Ticket::->paginate(10);

22nd July, 2017

Ricardo left a reply on Sending Recurring Emails With Schedule Determined By User Input • 4 months ago

Hola @jamescastro, if I were you I would have a due_date column, and every day I would query by due_date. After and email sent, the due_date is re-calculated. You need to have an initial due_date calculation.

21st July, 2017

Ricardo left a reply on Output Of Scheduled Jobs • 4 months ago

@timgavin any *nix command with > '/dev/null' 2>&1 means that the stdout is redirected to /dev/null - the hyperspace - 2means the stderr >& the file pointing to, and 1 is the stdout.

So, redirect stdout and stderr to /dev/null

Ricardo left a reply on Laravel 5.3 Echo Properties Of A Custom User • 4 months ago

@nanadjei2 or Auth::guard('admins')->user()depending of your the default

Ricardo left a reply on Database Structure Advice • 4 months ago

@lars6, someone point me of an interesting article for a separate table, reference table, (8 Reasons Why MySQL's ENUM Data Type Is Evil)[http://komlenic.com/244/8-reasons-why-mysqls-enum-data-type-is-evil/]. For sure things changed since 2011.

Ricardo left a reply on Laravel 5.3 Echo Properties Of A Custom User • 4 months ago

jeje @nanadjei2 it should be changed in config/auth in the providers section, but you always call:

{{ Auth::user()->username }}

you can configure what model Auth::user() should return.

Ricardo left a reply on Laravel 5.3 Echo Properties Of A Custom User • 4 months ago

@nanadjei2

{{ Auth::user()->username }}

;)

Ricardo left a reply on Database Structure Advice • 4 months ago

@lars6

If I don't split this up in a separated table I will have a lot of redundant data (see image above).

If I were you, I keep as is it now. If it were in a separate table, you'll have in this table type with the id of the other table, and type will be 1,1,1,2,1,2,1,2, etc. ("redundant data") and you need an extra query.

Ricardo left a reply on Database Structure Advice • 4 months ago

@lars6 since you are using where('type', 'worked_at') and where('type', 'working_at') you are asking to the database server to filter on that column, if is not indexed the server must see in all table rows; if it is indexed the server use it, so it is fasssterrr!

Ricardo left a reply on Database Structure Advice • 4 months ago

@lars6, sure. Here MIgrations.

in your migration:

$table->enum('type', ['worked_at', 'working_at'])->index();

Ricardo left a reply on Database Structure Advice • 4 months ago

@lars6 @phpMick or make it enum

Ricardo left a reply on Command - Best Option For Reminder Emails 2 Weeks Before Due Date Column • 4 months ago

@bashy if the due date is datetime it can be run twice one at 11:30pm, for example, and the other one at 11:58pm;

if due date is date it will run a near as possible to midnight.

My two cents.

Ricardo left a reply on Sync Databases In Different Servers • 4 months ago

@mohsen you can configure in config/databases more than one connection, say one for local and one for wordpress and you can do:

$wp_users = User::connection('wordpress')->where('id', '>', $user_local_max_id)->get();

20th July, 2017

Ricardo left a reply on Cleaner Auth::attempts • 4 months ago

@JuanRangel, second pass:

public function login()
{
    $email    = request()->email;
    $password = request()->password;
    $remember = request()->remember;

    if (! Auth::attempt(request(['email', 'password']), $remember, false)) { // check if use is in database
        return redirect('/login')->withErrors([
            'email' => 'These credentials do not match our records. Please try again.'
        ]);
    }

    $user = App\User::where('email', $email)->first();

    if ($user->disabled) { // checks if user is disabled
        return redirect('/login')->withErrors([
            'email' => 'Your account is disabled.'
        ]);
    }

    if ($user->verified) { // checks that user has been verified
        return redirect('/login')->withErrors([
            'email' => 'Your account is not active.'
        ]);
    } 

    return redirect('/dashboard');
}

Ricardo left a reply on When To Add A Leading Or Trailing Slash When Defining Route? • 4 months ago

@thebigk

Route::get('threads/create', '[email protected]');

Does the type of request 'get' or 'post' affect the route?

Route::get('threads/create', '[email protected]');
Route::post('threads', '[email protected]');

Ricardo left a reply on Cleaner Auth::attempts • 4 months ago

Hola @JuanRangel, one quick refactor:

public function login()
{
    $email    = request()->email;
    $password = request()->password;
    $remember = request()->remember;

    if (! Auth::attempt(request(['email', 'password']), $remember, false)) { // check if use is in database
        return redirect('/login')->withErrors([
            'email' => 'These credentials do not match our records. Please try again.'
        ]);
    }

    if (! Auth::attempt(['email' => $email, 'password' => $password, 'disabled' => 0], $remember, false)) { // checks if user is disabled
        return redirect('/login')->withErrors([
            'email' => 'Your account is disabled.'
        ]);
    }

    if (! Auth::attempt(['email' => $email, 'password' => $password, 'verified' => 1])) { // checks that user has been verified
        return redirect('/login')->withErrors([
            'email' => 'Your account is not active.'
        ]);
    } 

    return redirect('/dashboard');
}

Ricardo left a reply on Delete Item In Collection Array • 4 months ago

@kossa

$key = $c->search(function($item) {
    return $item->id == 2;
});

$c->pull($key);

But you can filter the collection:

$c = $c->filter(function($item) {
    return $item->id != 2;
});

Ricardo left a reply on Run A Cronjob To Execute Queue • 4 months ago

uhmm... given your current situation, @JeroenOnline, take a look at queue:restart command.

Ricardo left a reply on Sync Databases In Different Servers • 4 months ago

@mohsen

the schemes of tables are different

You can not have master-slave

If I were you, I will read from a Laravel the Wordpress User Table and sync it back.

Ricardo left a reply on How To Delete All The Data Of A Column In A Table • 4 months ago

Yes, @goatshark is right, it must be:

Product::where('quantity', '<>', 0)->update(['quantity' => 0]);

Ricardo left a reply on How To Delete All The Data Of A Column In A Table • 4 months ago

@nanadjei2 if you want to set quantity to 0 in all products, one way is:

Product::update(['quantity' => 0]);

Ricardo left a reply on CsrfToken Logout • 4 months ago

place this on head tag of your html

<meta http-equiv="refresh" content="30">

Ricardo left a reply on CsrfToken Logout • 4 months ago

@Marins that happens when the Csrf Token expired due to inactivity.

I suggest to add a page refresh every 30 minutes for example, that way the token never expires.

Ricardo left a reply on Command - Best Option For Reminder Emails 2 Weeks Before Due Date Column • 4 months ago

@bashy you're running the command once per day, I suppose, I can not see why duplication will happen if you are filtering by equal to today plus two weeks.

I have three of this commands without any additional field.

18th July, 2017

Ricardo left a reply on Ordering Issue • 4 months ago

@ro.it

To see what sort is use this:

public function products(Request $request,$category_url,$sort= 'ASC')
{
    dd($sort);
    ...
}
Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.