Ricardo

at Self employée - Two SaaS

Experience

102,520

43 Best Reply Awards

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

10th May, 2018

Ricardo left a reply on WHERE, Has, OrHas And More • 1 month ago

Thank you @Swaz

Ricardo started a new conversation WHERE, Has, OrHas And More • 1 month ago

Hi there, given the following query:

$books = Book::where('author_id', 957444)
    ->has('comedy')
    ->orHas('drama')
    ->get();

That author has 25 books in total including three comedy books and two drama books.

What I thought I would get was all the author's comedy or drama books with author_ id 957444, right? 5?

Let's take a look at the SQL generated:

select * 
from `books` 
where 
    `author_id` = 957444 
    and exists (select * from `types_one` where `books`.`type` = `types_one`.`id`) 
    or exists (select * from `types_two` where `books`.`type` = `types_two`.`id`)

Sure you're seen the problem. author and exists or exists give as all books no matter of the author. (More than a billon)

The expected SQL:

select * 
from `books` 
where 
    `author_id` = 957444 
    and (
        exists (select * from `types_one` where `books`.`type` = `types_one`.`id`) 
        or exists (select * from `types_two` where `books`.`type` = `types_two`.`id`)
    )

Grouping both exists with () will give the expected result 5 books.

Then the question is what I'm missing in the eloquent query

29th April, 2018

Ricardo left a reply on How To Encrypt My Id In URL Like This. • 1 month ago

@sun the term to describe your request is commonly known as ofiscation you can se here. I use Optimus

5th April, 2018

Ricardo left a reply on Migrate Fails On Deploy • 2 months ago

@thitami You may need to creare the database first.

19th March, 2018

Ricardo left a reply on Array Collection • 2 months ago

@kidi

$roles = Role::pluck('name', 'id')
    ->transform(function($name, $key) { 
        return ['value' => $key, 'name' => $name]; 
};)

11th February, 2018

Ricardo left a reply on Passing Data To View Vs Fetching With Ajax • 4 months ago

@druc if I were you I'll pass the 300 items.

Ricardo left a reply on Where Can I Define Global Helper Functions? • 4 months ago

@tptompkins for sure you are adding the corresponding elixir call to load you compiled app.js. ¿didn't you?

30th January, 2018

Ricardo left a reply on Inner Join In Eloquent • 4 months ago

use App\Product;
...
$products = Product::with('manufacturers')
    ->where('manufacturers.name', 'like', $needle)
    ->orWhere('products.name', 'like', $needle);

23rd January, 2018

Ricardo left a reply on How To Paginate An Eager Loaded Relationship? • 4 months ago

@thebigk in the first part, you have two queries, one for the thread, one for 10 paged answers; in the second you have two queries, one for the thread, one for all the answers.

If I were you, I would choose the first approach, with no additional work to do.

14th January, 2018

Ricardo left a reply on Is Possible To Use Where() And WhereBetween() • 5 months ago

$nalozi = Nalog::whereBetween('rokisporuke',[request('od'),request('do')])
    ->where('created_at', $now)
    ->orderBy('rokisporuke', 'ASC')
    ->get();

14th October, 2017

Ricardo left a reply on How To Get Answers To The Questions ? • 8 months 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? • 9 months ago

@shawnyv take a look at PHP eval function.

18th August, 2017

Ricardo left a reply on Laravel-mix Http / Https • 10 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 • 10 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 • 10 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 • 10 months ago

@Corbin

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

Ricardo left a reply on CLI Application With Laravel • 10 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 • 10 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 • 10 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 • 10 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 • 10 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 • 10 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 • 10 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 • 10 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 • 10 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 • 10 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 • 10 months ago

@Darkcoder as @Snapey says:

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

Ricardo left a reply on Understand Relations • 10 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 • 10 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 • 10 months ago

@tk90 uhmm... se here

Ricardo left a reply on Understand Relations • 10 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 • 10 months ago

@mattnewark

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

22nd July, 2017

Ricardo left a reply on Sending Recurring Emails With Schedule Determined By User Input • 10 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 • 10 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 • 10 months ago

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

Ricardo left a reply on Database Structure Advice • 10 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 • 10 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 • 10 months ago

@nanadjei2

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

;)

Ricardo left a reply on Database Structure Advice • 10 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 • 10 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 • 10 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 • 10 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 • 10 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 • 10 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 • 10 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');
}

Edit Your Profile
Update

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