pmall

Bioinformatics engineer at Lyon, France

Experience

583,445

683 Best Reply Awards

  • Member Since 3 Years Ago
  • 44 Lessons Completed
  • 0 Favorites

16th January, 2017

pmall left a reply on To "Repository Pattern" Or Not? • 1 year ago

Usually if you don't have a clear reason for using a pattern, then you don't need it.

Eloquent + scopes are fine for me. If you have complex eloquent construction you want to reuse you can wrap it in a scope.

pmall left a reply on Possible To Have A HasMany As Well As A HasOne Relationship With The Same Model? • 1 year ago

It works perfectly. But here you will have the administrator in the regular user list. If it is the intended feature, everything is fine.

pmall left a reply on With A HasMany Relationship, How To Get Only The Parents Without The Children? • 1 year ago

I don't understand. Parent::all() return only parent models. If you don't ask eloquent to retrieve relationship it wont.

9th January, 2017

pmall left a reply on Dynamic Content For Download (Content-Disposition The Laravel Way...) • 1 year ago

I'm sure I can reduce it to 1 line or even create a quick shortcut method somewhere.

Third parameter of the response object/helper is an associative array o headers :

$response = response('File contents', 200, [
    'Content-Type' => 'application/json',
    'Content-Disposition' => 'attachment; filename="myfile.txt"',
]);

pmall left a reply on Dynamic Content For Download (Content-Disposition The Laravel Way...) • 1 year ago

Object retuned by response() does not expose a headers property.

How to manage headers is explained here https://laravel.com/docs/5.3/responses#creating-responses

pmall left a reply on Dynamic Content For Download (Content-Disposition The Laravel Way...) • 1 year ago

But what is the bug when you do this?

pmall left a reply on Dynamic Content For Download (Content-Disposition The Laravel Way...) • 1 year ago

it didn't work

Be more specific please :)

pmall left a reply on Streaming A File For Download (Content-Disposition The Laravel Way...) • 1 year ago

Here you're not streaming the file. The whole file is generated and stored in memory as you have a $fileContent variable.

The only way to stream a csv is to use Symfony\Component\HttpFoundation\StreamedResponse with a callback generating the content.

pmall left a reply on Fill A Form By Entering Primary Key • 1 year ago

Please be more specific. What have you tried to do?

pmall left a reply on How To Design OO Applications. • 1 year ago

With laravel designs patterns are already set up for you. Except if you have a very very specific requirement, anything a web app can require fits in some laravel feature.

pmall left a reply on Using Var As Relationship Name • 1 year ago

No idea. Why do you use a variable attribute?

pmall left a reply on Digital Ocean - Traffic • 1 year ago

You will always end up paying for the bandwidth of your website if it gets a lot of traffic.

pmall left a reply on Using Var As Relationship Name • 1 year ago

please show the code

6th January, 2017

pmall left a reply on How Delete All "throug" Relations Without Foreach? • 1 year ago

You have no choice but loop over the object. Whats the problem with foreach ?

@SaeedPrez matches collection doesn't have a goals() relationship.

pmall left a reply on Routing Problem • 1 year ago

@iGenezys the route of your localhost must be your public folder.

pmall left a reply on How To Use Function In Eloquent Query? • 1 year ago

how do I go about querying the model using the 'isLive()' function to filter through results?

This is totally impossible. You cant "pass" php code to sql.

You must use a where clause, probably by using a boolean column.

pmall left a reply on Can See Site Via Domain Name But Not Via IP Address • 1 year ago

This is perfectly normal your virtual host is configured to respond to request with your domain name as hostname.

pmall left a reply on How To Register A Service Provicer Dynamically? • 1 year ago

There is no way really. You will need at some point to register it.

You can distribute a base application which test if some service providers exists and if any register them.

pmall left a reply on How To Register A Service Provicer Dynamically? • 1 year ago

The question is why do you want to do this?

There is no magical method, if you want to configure a package you need to write something somewhere at some point.

pmall left a reply on How To Use Eloquent In A Validation Rule • 1 year ago

The exists rule?

5th January, 2017

pmall left a reply on More Elegant Way To Handle Properties Of Null Object • 1 year ago

Do not hide errors, it is ugly as hell! What if another errors is produced when using avatar->url?

@MikeHopley solution is obviously better. Or you can handle it the regular way : a method hasAvatar() and a conditional.

4th January, 2017

pmall left a reply on Check If Model Exists For Use In Custom Method • 1 year ago

You should delegate the processing of a model to another object.

$processed_object = new CampaignReachProcessor($campaign);

pmall left a reply on Assign Unserialize Laravel Object To JS Array • 1 year ago

var branches = {!! json_encode(unserialize($preliminary->branches)) !!};

pmall left a reply on How Check If Record Is Exit And Soft Delete • 1 year ago

can you please tell me how to do the soft delete

Just read the doc about soft delete. Once you put the traits in your model you just call delete() like your code above.

pmall left a reply on Where I Put My Custom Functions To Be Accessed In View (laravel 5.3)? • 1 year ago

You can also set custom blade directives (check the docs) so you can directly write something like @romanic_number($n) in you views.

pmall left a reply on Passing User Id To A Many To Many Relationship • 1 year ago

You just have to set up a relationship between User and Place and use it :

@foreach (auth()->user()->places as $places)
//
@endforeach

pmall left a reply on Vuejs: Separate Requests To Separate Routes Vs. Post To An Update Route - What Is Better Design In Your Perspective? • 1 year ago

Why not sending a put/patch method (you're obviouly modifying an entity) with the data you want to update? If you change the status just send the new status value.

pmall left a reply on Custom 'exists' Validator For Hashed Ids • 1 year ago

You can make custom validation rules. Check the docs.

Also you can use the form request to decode your id :

// in the form request
public function all()
{
    $this->merge(['user_id' => decode($this->user_id)]);
}

pmall left a reply on How Check If Record Is Exit And Soft Delete • 1 year ago

$dlesson = Lesson::findOrFail(input::get('id'));

$dlesson->delete();

pmall left a reply on Modern Dev Forces Me To JS When I Want To PHP. • 1 year ago

Whats so different in making an api or an html app? Returning json instead of html?

But I agree, I don't like all this JS thing. I usually try to put the less possible javascript in my apps, just the minimum required. It ends up in multiple pages with some javascript component into it.

Look at this successful laracast website for example, it is perfectly fine and it is not api/js only.

pmall left a reply on Right Way To Validate Form Input Fields • 1 year ago

Create a form request and make an array with 52 rules.

What is strange is not to validate 52 fields, it is to have 52 fields.

pmall left a reply on Validation With Two The Same Rules And Different Error Messages • 1 year ago

Create a custom rule for email_verified, then you can assign it a custom message.

3rd January, 2017

pmall left a reply on Service Provider And Db Query • 1 year ago

Why do you want to run queries in a service provider?

pmall left a reply on Delete Event Not Fired • 1 year ago

The bug in your first post was that $user->documents() returns a query builder and not a collection. To get the collection of documents you have to use $user->documents.

$user->documents()->delete(); doesn't fire event because it is just running a sql query for deleting those rows in the database. Events are fired when you actually use the delete method of a model.

pmall left a reply on Query From Two Tables With 'Where' Conditions • 1 year ago

as I don't have location model

Well you should have one ^^

Also you can change the key of the relationship so the key is the location column.

pmall left a reply on Query From Two Tables With 'Where' Conditions • 1 year ago

This is not a problem with the query but your website design. I don't understand in which way you think doing ($agent->location == $order-location) is different from a relationship and how it would solve your 100 agent problem.

pmall left a reply on Query From Two Tables With 'Where' Conditions • 1 year ago

I'm not sure what you want exactly. ($agent->location == $order-location) mean all the agents for a given location so a simple relationship between loaction and agent will do the trick.

pmall left a reply on Query From Two Tables With 'Where' Conditions • 1 year ago

In fact you have a triple sided relationship. Your base should be structured like this :

  • OrderLocation model which belongs to an Order and a Location and belongs to many User.
  • Order model which has many OrderLocation
  • User which belongs to many OrderLocation

Choose a suitable name for OrderLocation. Then you can do:

@foreach ($orders as $order)
// you can do something with $order there
@foreach ($order->order_locations as $order_location)
// you can do something with the $order_loaction->loaction there
@foreach ($order_location->agents as $agent)
<option value="{{ $agent->id }}">{{ $agent->name }}</option>
@endforeach
@endforeach
@endforeach

OrderLocation model represent a couple of order and location which is you are actually focusing on.

pmall left a reply on Query From Two Tables With 'Where' Conditions • 1 year ago

This is simply chaining relationships :

@foreach ($orders as $order)
@foreach ($order->location->agents as $agent)
<option value="{{ $agent->id }}">{{ $agent->name }}</option>
@endforeach
@endforeach

Order belongs to Location, Location has many User.

Then to scope it to the 3 status :

$orders = Order::with(['location.users' => function ($query) {

    $query->whereStatus(3);

}])->get();

23rd December, 2016

pmall left a reply on Is There A Size Limit On Requests? • 1 year ago

I had problems when trying to send thousands of post fields at the same time (wried I know but required). The solution I came up with is to serialize them into one field then unserializing them when receptioning it.

Servers can also have limitation for the size of the input, but it can be configured.

16th December, 2016

pmall left a reply on Should This Code Be In The Controller? (google Charts Back-end) • 1 year ago

really shows me how much of Laravel I need to learn

This is not especially laravel feature. With any language when you think some piece of code doesn't belong at some place, you can always extract it to its own class.

15th December, 2016

pmall left a reply on How Can I Keep Content Consistent? • 1 year ago

Why do you let the user enter the start time? isnt it equal to the previous end time (or now if it is the first).

pmall left a reply on How Validate Url With Or Without Http, Https, Www • 1 year ago

There is built in php functionality:

$is_url = filter_var($url, FILTER_VALIDATE_URL) !== false

12th December, 2016

pmall left a reply on Get Storage Url... • 1 year ago

You just have to put a simlink from your public folder to your storage folder.

Example : public/avatars => storage/app/public/avatars. Then store your files in storage/app/public/avatar and access them from http://yourdomain.com/avatars/...

pmall left a reply on Problem With Blade And @extends • 1 year ago

You should review your logic, having a conditional layout is really messy.

pmall left a reply on Notifications -- Times Wrong • 1 year ago

Same as @Snapey - I got 6 hours ago living in france, @willvincent gets it in the future living in usa, definitively a timezone thing.

pmall left a reply on Code Blocks Not Colored On First Load • 1 year ago

For me code almost never get highlighted. At least make the default code block color white, not drakgrey on black!

pmall left a reply on Form Validation: Custom Error Message With Input Value • 1 year ago

@philwgreen @thirtythree the only way is to create a custom validation rule with a custom message :

use Illuminate\Validation\Validator as BaseValidator;

class Validator extends BaseValidator
{
    protected function validateUniqueName
    {
        // Return boolean, can make use of parent validator validateUnique method.
    }

    protected function replaceUniqueName($message, $attribute, $rule, $parameters)
    {
        $name = Arr::get($this->data, $attribute);

        return str_replace([':name'], [$name], $message);
    }
}

And of course you must have a custom error message for unique_name rule containing placeholder to replace : 'unique_name' => ':name has already been registered to another team.'.

9th December, 2016

pmall left a reply on Controller Or Model Method • 1 year ago

Why not having a relationship between Contry and Hollyday?

8th December, 2016

pmall left a reply on Get Accessor "virtual" Field From View • 1 year ago

in view there is not

?

Just do $model->name.

Edit Your Profile
Update

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