jeudi 1 mars 2018

How to tell Deployer to use different PHP version once ssh'ed to my shared hosting?

I'm experimenting with Deployer to deploy Laravel application into shared hosting (using laravel recipe) from my local ~/Code/project_foo.

The point is that when I'm connected to my shared hosting server via ssh, then default php -v version is 5.6.33. I confirmed that I can change php version on fly by calling php70 -v or even whole path like /usr/local/bin/php70 whatever.

The point is that I don't know how to tell deployer to call commands using php70 which is required, otherwise composer install fails.

enter image description here

So in Terminal I'm inside root of the Laravel project and I simply call:

dep deploy

My deploy.php is messy and very simple but this is just a proof of concept. I'm trying to figure out everything and then I will male it look nicer.

enter image description here

I checked the source code of the laravel recipe, and I saw that there is:

but I don't know how to override the value to match what my hosting tells me to use:

/usr/local/bin/php70

Please, give me any hints how to force the script use different PHP version once connected to the remote host / server.

This is whole script:

<?php
namespace Deployer;

require 'recipe/laravel.php';


//env('bin/php', '/usr/local/bin/php70'); // <- I thought that this will work but it doesn't change anything


// Project name
set('application', 'my_project');

// Project repository
set('repository', 'git@github.com:xxx/xxx.git');

// [Optional] Allocate tty for git clone. Default value is false.
set('git_tty', true); 

// Shared files/dirs between deploys 
add('shared_files', []);
add('shared_dirs', []);

// Writable dirs by web server 
add('writable_dirs', []);


// Hosts

host('xxx')
    ->user('xxx')
    ->set('deploy_path', '/home/slickpl/projects/xxx');

// Tasks

task('build', function () {
    run('cd  && build');
});

// [Optional] if deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');

// Migrate database before symlink new release.

before('deploy:symlink', 'artisan:migrate');



via Chebli Mohamed

Laravel get data from dropdown list and pass it to the controller

I am trying to have the user choose a month from a dropdown list displaying the months, and passes that month value (in numbers) to the controller I am having trouble making the dropdown list an action so once the user picks the month, the controller gets called.

here is my index page:

  <h>Display a logs by monthly <h>
    
    <a href=""  class="btn btn-primary">Monthly Logs
      </a>

and when I add the Form method inside the tag i am getting an error says the variable is not defined.

here is the Controller.php

 public function monthly($id)
 {
     $dcmlogs = log::with('users')
     ->whereMonth('created_at', '=', $id)
     ->paginate(15);
    return view('dcmlog.index', compact('dcmlogs'));
}



via Chebli Mohamed

How to remove multi Language folder-name

Our site uses /language/ folder to route multilingual translations to right folder. Then it automatically removes the folder/parts from the address.

I want to remove "/language/" part from address ie. site.com/language/es ...so that I can use site.com/es as the address instead of site.com/language/es

Sam



via Chebli Mohamed

Laravel Form Request validation not working with getValidatorInstance()

I've a simple array of rules in rules function:

return [
    'anumber'  => 'required|numeric'
];

And I fill this in getValidatorInstance method this way:

request()->merge(['anumber' => IdsCompany::getNumDBempty()]);

By the way, getNumDBempty() is working as expected, and returns an int or 'false', I want the validator only accept the request if the function returns a number.

The thing is that 'anumber' is merged with the request but it keeps telling me that 'anumber' is compulsory.

I've fighting and searching for a couple of days, and I don't find any clue of why the validator don't work on variables merged in getValidatorInstance(). (I've tried to validate this in others FormRequest and the result is the same, they ignore it like the variable was never there, but the request has it inside.)

Working in Laravel 5.5 atm, and planning to upgrade 5.6 when my form request are done and working.

Thank you all in advance! Have a good Thursday!



via Chebli Mohamed

Convert attribute to string before saving (during update) (5.4)

I've had a look at serialization after the model is loaded from the database using protected $casts, but we have a slightly different situation. What I'm trying to figure out is how to use serialize() function to save model' attributes instead of json_encode and not having much luck. Using accessors does not work since it's only for the accessing the data, not for doing post-load-from-database conversion. Are there any examples of how this can be done? The only one I can think of is the subscription to the event, but this is going to be messy.



via Chebli Mohamed

Internal Server Error: Laravel CentOs 7

I have uploaded my Laravel Project on the Server which CentOs 7. But after migrating the project i got the Error as shown in following screenshot:

enter image description here

I have Clear the Cache, also allow the permission to storage folder and update the composer and i have tried Many Stuff in order to solve but unfortunately none of them work form me.

Your Effort will be appreciated. Thanks,



via Chebli Mohamed

mercredi 28 février 2018

excessive delay in queue - laravel

Goodnight I need to send more than 1000 emails for each event created, and for this I use queue (as Laravel's documentation says), but when sending the emails I have to wait until all the emails are sent to return to the view of control Panel

this is my "store" function in NewsEvents.php controller that sends the emails

 public function store(Request $request)
{
    $attributes = request()->validate(News::$rules, News::$messages);

    $news = $this->createEntry(News::class, $attributes);

    //queue for sending emails 
     $this->dispatch(new Nevent($news));


    return redirect_to_resource();
}

the "handle" function of job "Nevent.php"

 public function handle()
{
    //   
     $users=User::where('tipo_user','user')->get();                  
         foreach($users as $user)
         {
             $user->notify(new EventCreated($this->news));
             echo 'enviado correo';
             Informe::create([
                'event_id' => $this->news->id,
                'total' => '1',
                'tipo' => 'invitacion',
                'dst_id' => $user->id,
                'estado' => 'correcto',
            ]);

         }
}

What could be the problem?



via Chebli Mohamed