notflip

Experience

3,020

0 Best Reply Awards

  • Member Since 1 Year Ago
  • 17 Lessons Completed
  • 0 Favorites

17th May, 2017

notflip started a new conversation Laravel Edit Product, Set Correct Selected (with Many-to-many) • 5 months ago

I have a system where a User has Shops and Shops have Products.

Now a Shop can have many Products, and a Product can belong to many Shops. When a User adds a new Product he/she can choose for which Shop he/she wants to add it

Shops

+----+---------+----------------+
| id | user_id |      name      |
+----+---------+----------------+
|  1 |       1 | My First Shop  |
|  2 |       1 | My Second Shop |
+----+---------+----------------+

Shop_Products

+---------+------------+-----------+
| shop_id | product_id |   image   |
+---------+------------+-----------+
|       1 |          1 | beer.jpg  |
|       1 |          2 | wine.jpg  |
|       1 |          3 | vodka.jpg |
+---------+------------+-----------+

My issue is when a User edits a Product I want to pre-populate the Shop select dropdown with the current Shop this product is assigned to..

But offcourse the following query returns a Collection hence the many-to-many

$product = Product::findOrFail($id)->shops

in my view, to set the correct select option selected I'm trying the following

@foreach(\Auth::user()->shops as $shop)
    <option value="{{ $shop->id }}" @if($shop->id == $product->shop->id) selected @endif>{{ $shop->description }}</option>
@endforeach

$product->shop->id isn't working, because $product->shop is a collection

Looking forward to your ideas! Thank you

15th May, 2017

notflip left a reply on Mailgun Connection Timed Out, While Not Using Mailgun Driver. • 5 months ago

This is not working :( same error about a timeout to mailgun keeps popping up. So weird! It's happening with all queued jobs that have to send mails.

notflip started a new conversation Mailgun Connection Timed Out, While Not Using Mailgun Driver. • 5 months ago

Hi,

I'm getting the following error when trying to send out mails

Swift_TransportException: Connection to tcp://smtp.mailgun.org:465 Timed Out in /var/www/assessment/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:404

I removed everything I could relating to Mailgun and it's still throwing this error, any idea what might be going on here?

This is my .env

MAIL_DRIVER=ses
MAIL_HOST=email-smtp.eu-west-1.amazonaws.com
MAIL_PORT=587
MAIL_USERNAME=#secretusername#
MAIL_PASSWORD=#secretpassword#
MAIL_ENCRYPTION=tls

this is my config/mail.php

'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',

11th May, 2017

notflip left a reply on Best Way To Load Javascript On A Per Page Basis? • 5 months ago

@milon How would you do that using Webpack? Can't imagine you can split it off per page?

27th April, 2017

notflip left a reply on Laravel Valet 403 Forbidden Error • 5 months ago

@jamestowers Thanks! Working solution

20th April, 2017

notflip left a reply on Laravel Relation For Different User Types • 5 months ago

@thoasty Thanks for your answer! Why does the if break eloquent features?

notflip left a reply on Laravel Relation For Different User Types • 5 months ago

Thanks! @tisuchi I was thinking of that approach, But can't translate the example to my situation.. Would the User have the userable_id and userable_type for example?

notflip started a new conversation Laravel Relation For Different User Types • 5 months ago

I have a platform where I have Users that are a Shop, they can place Orders, and I have Users that are Suppliers, they can view the placed Orders.

Now I'm running into some logic issue's, for example in my User class I woud like for the Supplier to be able to do this

Auth::user()->orders

But the User that is a shop should also be able to do this

Auth::user()->orders

I illustrated a bad example on how to do this here:

class User extends Authenticatable
{
  public function orders()
  {
      return $this->hasMany(Order::class, 'created_by');
  }

  public function alsoHasOrders()
  {
      return $this->hasMany(Order::class, 'fulfilled_by');
  }

}

There should be a better way to do this right?

12th April, 2017

notflip started a new conversation Custom Validation Message For Exists • 6 months ago

Is it possible to define a custom message for the exists:table,id rule? I tried the following

public function messages() { return [ 'items.*.product_id' => [ 'exists'=> 'Not found' // not working 'exists:products' => 'Not found' // not working 'exists:products,id' => 'Not found' // not working ] ]; }

24th March, 2017

notflip left a reply on Npm Run Watch In Infinite Loop (Laravel 5.4) • 6 months ago

Did you find a solution to this? I also have the loop issue.

14th March, 2017

notflip left a reply on Daemon Workers Reset With Envoyer • 7 months ago

Is it possible using only Envoyer? setting up the queue workers?

12th March, 2017

notflip left a reply on Laravel 5.4 Markdown Email Character Issue • 7 months ago

Yes! don't indent the code. :)

9th March, 2017

notflip left a reply on Nested Resources Controllers Structure • 7 months ago

What I you need the nesting, for example

/admin/clients/cocacola/categories/general/questions/1

How would we go about this? or is using a resource controller the best option? How about custom methods? thanks!

10th February, 2017

notflip started a new conversation Laravel 5.4 Markdown Email Character Issue • 8 months ago

I'm using Laravel 5.4, I'm sending a Markdown mailable with the following code:

public function build()
{
    return $this->markdown('emails.userWasRegistered')
        ->with('user', $this->user);
}

This is the markdown

@component('mail::message')

    # Welcome

    Thank you for registering, you are registered as a {{ $user->role }}

    @component('mail::button', ['url' => $url])
    Login
    @endcomponent

@endcomponent

But the output isn't what it's supposed to be, right?

This is the html https://i.stack.imgur.com/2qKSp.png

This is the html source https://i.stack.imgur.com/1brNy.png

Any idea what might be going wrong? Thank you!

1st February, 2017

notflip started a new conversation Queued Event Callback When Done? • 8 months ago

I'm using the following code to have an event run in the background (sending emails)

class SendEmailToRegisteredUser implements ShouldQueue
{

    public function handle(UserWasRegistered $event)
    {
        Mail::to($event->user)->send(new UserWasRegisteredMail($event->user));
    }
}

This is working fine, it's looping through my list of employees, sending them mails. Now I'm wondering

I have a status icon next to each employee, which should turn green when the email is sent, do queues have a callback? Can I green these up once the mail is gone?

Thank you!

30th January, 2017

notflip started a new conversation 5.4 Markdown Doesn't Render HTML • 8 months ago

I'm wondering if anyone else is having this problem? When viewing a markdown mail in Mailtrap, all html is escaped. It's just rendered as text.

http://imgur.com/a/0537q

Any idea if I might be doing something wrong? Thank you!

26th January, 2017

notflip started a new conversation Creating A DateRange From Records With Start And End • 8 months ago

I'm trying to implement some good practice oop!

I have a database with multiple rows that have a start and end, Now I need to compare if there is no row that overlaps.

To do this I'm guessing I have to loop all rows

But is it possible to generate a DateRange object from each row? I mean is there a good way to go about this?

Thank you! Looking forward to your reactions

11th January, 2017

notflip started a new conversation Many-to-many With ID And Relation, How Would The Model Look? • 9 months ago

I'm trying to build a database where an admin

Can create lists that have can have tasks, now the tricky part is, all users can set tasks as completed, but only for himself.

Here's my current scheme

http://imgur.com/a/x6cwo

I'm trying to get the models working with the following

User.php

 public function blocks()
{
    return $this->hasMany(Block::class, 'user_path_blocks');
}

But it's failing and I can't find why. Anyone who sees what I'm doing wrong?

10th January, 2017

notflip left a reply on Building Complex Seeders With Factories • 9 months ago

Well I don't really know how to nest relations that deep, So the ClientsTableSeeder needs to create categories, for each category some questions, and for each question some answers, while also adding the original user_id to the answers for example.

Can't really find a good tutorial/resource on this.

notflip started a new conversation Building Complex Seeders With Factories • 9 months ago

Hi guys!

I've been stuck in the docs and tutorials for days now!

I have a survey website, with users posting answers to question, that are in categories.. Few!

I'm trying to create an entry in the answers table, that has - user_id - question_id

The questions table has - question_name - category_id

the categories table has - category_name - client_id

So is this possible? Or is it to much to ask from the Factories and the Seeders?

Thank you!

12th December, 2016

notflip started a new conversation Where In HasMany Relation • 10 months ago

Hi,

I have 2 types of users, coaches and employees.. I'm using Roles (https://github.com/spatie/laravel-permission), comparable to entrust

Now I'm wondering if I can make the following work:

public function employees()
{
    return $this->hasMany(User::class); // -->hasRole('employee');
}

public function coaches()
{
    return $this->hasMany(User::class); // -->hasRole('coach');
}

Is there a general way to querying a relation with another relation? Oh and If I'm doing this the wrong way, please let me know!

7th December, 2016

notflip left a reply on Soft Deleting With Relations • 10 months ago

In what file is this happening? thanks!

6th December, 2016

notflip left a reply on Using 3 Authenticatable Entities, Seperate Auth Or With User? • 10 months ago

Thanks, I got it working, I'm just wondering.

Isn't this dangerous for getting the wrong type? I I would assume that

$user->userable->data is set, but I don't know what kind of 'userable' the User is. Do you know what I mean?

Thanks for your advice by the way!

notflip left a reply on Using 3 Authenticatable Entities, Seperate Auth Or With User? • 10 months ago

@pmall Could you please explain the polymorphic relation? I was just going with belongsTo, should I use the polymorphic ones?

notflip started a new conversation Using 3 Authenticatable Entities, Seperate Auth Or With User? • 10 months ago

Hi,

Looking for some good practice advice here, I have 'admins', 'employees', and 'coaches'. They will all have to login, but have some different data in the db, and different roles and permissions.

Is it good practice to have a Users table which holds all users, and then couple each user to it's type with a relation..

So Auth::user()->admin would give me access to his admin fields.

Or are there better options? This seems like a good one because only one table handles Authentication.

Looking forward to your responses!

30th November, 2016

notflip started a new conversation Human Readable Dates In The Near Future • 10 months ago

Hi,

I've been using Carbon for a while (and it's great) but I'm wondering if there's a similar tool for fomatting dates in the future, such as :

"Today, 6:00pm" "Tomorrow, 12:30pm" "Wednesday, 4:00pm" "Next friday, 11:00am"

Carbon returns "4 days after", when using dates in the future.

Thank you!

notflip started a new conversation Laravel Exception Handler, Log When Using Catch() • 10 months ago

Hi, I'm using a Geocoder to get an address, when no address is found I catch the error and continue the loop, I don't want the user to be interrupted However when I catch, I see it doesn't get logged? It doesn't pass the Exception/Handler.php? Any idea how I should go about this? Thank you!

29th November, 2016

notflip started a new conversation Change The Format Of A Date Before Saving? • 10 months ago

I have a date that's being selected in a datepicker in the following format using AM/PM

Y-m-d g:i A

When I submit the form offcourse Laravel won't update the record because the format is unknown to my DATETIME field in mysql.

I tried using a Mutator on my Model as following, without success

public function setDateAttribute($value)
{
    $this->attributes['date'] = Carbon::createFromFormat('Y-m-d g:i A', $value)->format('Y-m-d H:i:s');
}

The original value is not being updated. Any idea what I might be doing wrong?

Thank you

25th November, 2016

notflip started a new conversation Repository For Dentist And Patient Appointments • 10 months ago

Hi,

I'm making a shared controller for dentists and patients, to show their appointments. I made a repo to keep the controller clean and added the following methods to begin.

I'm wondering, is this good practice? The right way to go about this? Looking forward to your ideas!

class AppointmentRepository
{

    private $appointment;

    public function __construct(Appointment $appointment)
    {
        $this->appointment = $appointment;
    }

    public function getAll()
    {
        return $this->appointment->all();
    }

    public function getAllByDentistId($id)
    {
        return $this->appointment->where('dentist_id', $id)->get();
    }

    public function getAllByPatientId($id)
    {
        return $this->appointment->where('patient_id', $id)->get();
    }

    public function getOneByDentistId($dentistId, $appointmentId)
    {
        return $this->appointment->where('dentist_id', $dentistId)->where('id', $appointmentId)->first();
    }

    public function getOneByPatientId($patientId, $appointmentId)
    {
        return $this->appointment->where('patient_id', $patientId)->where('id', $appointmentId)->first();
    }

    public function getConfirmedByPatientId($id)
    {
        return $this->appointment->where('patient_id', $id)->confirmed()->get();
    }

    public function getConfirmedByDentistId($id)
    {
        return $this->appointment->where('dentist_id', $id)->confirmed()->get();
    }
}

24th November, 2016

notflip left a reply on Seperate Roles In Different Models Or Use Only User? • 10 months ago

Well a Doctor will have it's own information like address, opening hours, ... A patient will have a medical history, and an admin is just an admin.

How would you go about that? Make a relation with a doctor-data table for example? Doesn't sound like a good plan. Thanks for your time

notflip started a new conversation Seperate Roles In Different Models Or Use Only User? • 10 months ago

I'm making a platform that will have "admins", "patients", and "doctors". I'm using a roles-based package but I'm wondering..

Should they all be "User"? or should I extend each one of the into it's own Model that extends Authenticatable?

Thank you!

26th October, 2016

notflip left a reply on Group By First Letter Of Last Name In Controller • 11 months ago

@Snapey This is working but for some weird reason it's automatically loading all my relations of say 'Customer' and also returning those. Is this normal?

notflip started a new conversation Create A Laravel Application Key For Each Machine? Or Add To .env • 11 months ago

Hi,

I'm working on a project with 2 persons, now i'm wondering do I include the application key my installation generated into the .env file.

Or does the next guy working on it have to generate his own key?

Thanks!

notflip left a reply on Inverse Relation On 2 Fields Not Working • 11 months ago

You can see what I've tried? It's underneath the code.. I tried with the method homeGames() and awayGames(). Thank you

notflip started a new conversation Inverse Relation On 2 Fields Not Working • 11 months ago

I have a football Game which has a home_team and an away_team

My relations for Game.php are as follows:

public function hometeam()
{
    return $this->hasOne(Team::class, 'id', 'home_team_id');
}

public function awayteam()
{
   return $this->hasOne(Team::class, 'id', 'away_team_id');
}

Now I want to see for each Team on which games it belongs.

I have a football Game which has a home_team and an away_team

My relations for Game.php are as follows:

public function hometeam() { return $this->hasOne(Team::class, 'id', 'home_team_id'); }

public function awayteam() { return $this->hasOne(Team::class, 'id', 'away_team_id'); } Now I want to see for each Team on which games it belongs. I've tried the following in Team.php but it's returning null

public function homeGames()
{
     return $this->belongsTo('App\Models\Game', 'home_team_id', 'id');
}

public function awayGames()
{
    return $this->belongsTo('App\Models\Game', 'away_team_id', 'id');
}

13th October, 2016

notflip left a reply on Laravel 5.3 This Password Reset Token Is Invalid • 1 year ago

So strange! You're right and I feel stupid now.

Thanks!

notflip started a new conversation Laravel 5.3 This Password Reset Token Is Invalid • 1 year ago

Hi, I'm using the out of the box password reset functionality with the make:auth command. Every time I try to submit the password reset form, where you insert a new password I get

This password reset token is invalid

In the view I see this weird line of code <input type="hidden" name="token" value="{{ "x" }}">

Shouldn't that X be something else? Like the reset token from the url?

Edit Your Profile
Update

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