mardi 21 février 2017

Laravel small differences for different environments

I have 3 projects that are very similar: 95% of the code. Now when I have to make an edit I have to copy that three times and It's very bad!

So I need to have only one project and manage the small differences with something like environments. But I dont't really know the good way.

For example I have a controller with this function

public function save()
    {
        $this->validate($this->request, [
            'firstname' => 'string',
            'lastname' => 'string',
            'gender' => 'string',
            'phone' => 'bail|size:10|required',
            'email' => 'email',
            'birthdate' => 'bail|date',
            'referral_code' => 'bail|string',
            'city' => 'bail|string',
            'call_state' => 'bail|string',
            'call_date' => 'bail|date',
            'campaign' => 'bail|string',
            'note' => 'bail|string',
            'overwritten_by_lead' => 'bail|integer',
            'change_state_counter' => 'bail|integer'
        ]);

        $data = $this->request->all();
        $customer = $this->repository->create( $data );

        return $this->response->item($customer, $this->transformer)->setStatusCode(201);
    }

and the difference with another project is:

public function save()
    {
        $this->validate($this->request, [
            'firstname' => 'string',
            'lastname' => 'string',
            'gender' => 'string',
            'phone' => 'bail|size:10|required',
            'email' => 'email',
            'birthdate' => 'bail|date',
            'referral_code' => 'bail|string',
            'city' => 'bail|string'
        ]);

        $data = $this->request->all();
        $customer = $this->repository->create( $data );

        return $this->response->item($customer, $this->transformer)->setStatusCode(201);
    }

Another difference inside entities are for example:

protected $fillable = [
        'firstname',
        'lastname',
        'phone',
        'email',
        'birthdate',
        'gender',
        'province',
        'zip_code',
        'address',
        'city',
        'campaign',
        'overwritten_by_lead',
        'change_state_counter',
        'call_state',
        'call_date',
        'credit',
        'referral_code'
    ];

And this is another

protected $fillable = [
        'firstname',
        'lastname',
        'phone',
        'email',
        'birthdate',
        'gender',
        'province',
        'zip_code',
        'address',
        'city'
    ];

Inside thhese three projects there are very little differences but I need to manage these.

I don't want to manage with many If because environment can be more than 3!

What is the best way to overwrite or to manage these difference into different environments with different files?

For example I have for project 1 inside a folder: CustomerController and CustomerEntity The same thing for the other project, inside every folder of an environment I put the files that are different, but how can I overwrite these files?

Thanks



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2l6uqQl
via IFTTT

Aucun commentaire:

Enregistrer un commentaire