vendredi 1 janvier 2016

Cant run a migration when deploying. Laravel 5.2

Consider the following task for envoy:

@task('deploy', ['on' => 'web'])
    cd personal_site
    php artisan down
    git pull origin master
    composer install
    php artisan migrate
    php artisan up
@endtask

php artisan migrate // Blows up

The error is:

[user@xxxx]: **************************************
*     Application In Production!     *
**************************************
[user@xxxx]: Command Cancelled!
[user@xxxx]: Application is now live.



via Chebli Mohamed

How to move my controllers into a seperate package folder in Laravel 5.2?

I build a small app using laravel 5.2. I put all of my files into a folder called Surveys located at App/Modules/Surveys. "No worries, I am planning to move the Modules out of the App folder, I just need to get the controller to work"

Currently my controller is located on App/Http/Controllers/SurveysController

I want to move my controller folder so it is located on App/Modules/Surveys/Controllers/Frontend/SurveysController

How would I tell laravel to resolve the controller out of this path App/Modules/Surveys/Controllers/Frontend/ instead of App/Http/Controllers?

I tried to do this into a service provider but it is still not working

<?php

namespace App\Modules\Surveys\Providers;

use Illuminate\Support\ServiceProvider;

class PackageServiceProvider extends ServiceProvider
{

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {

        if (! $this->app->routesAreCached()) {
            require __DIR__.'/../routes.php';
        }

    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {

        $this->app->make('Modules\Surveys\Controllers\Frontend\SurveyController');
    }

}

What should I do to make the routes point to the correct controller?

Just for clarity my Application instructor starts at the App

App/Https/Controllers App/Modules/Surveys



via Chebli Mohamed

Tumblr API createPost method error in laravel

Hi I am using Tumblr PHP client to make post into my Tumblr blog . I have created an app using laravel to post my content into Tumblr . I'm following this => http://ift.tt/13N9duT

but when i run this code

$client->createPost($blogName, $data);

it returns and error Error message :

FatalErrorException in RequestHandler.php line 86:
Cannot unset string offsets 

How can i solve this problem ? Thanks



via Chebli Mohamed

Laravel 5 Routes - Group domains if in array?

I have same project here(Laravel 5 Routes - Group Domains from Rows in Database), but I don't know how I should organize my code in routes.php and Custom ServiceProvider ? Can you help me ?

Finally, I want to check the domain with my array (As here), and put in custom view (with 403 code) if the domain is not present. And if exist, return in a variable the ID's domain value for to use it in all Request Eloquent.

Thx.

ps : Sorry for my english (French).



via Chebli Mohamed

Laravel lockforupdate (Pessimistic Locking)

i'm trying to figure out how to use/test the lockforupdate correctly, but i found is not function like what i expected

this is just testing

public function index() {
        return dd(\DB::transaction(function() {
            if (\Auth::guard('user')->check()) {
                $model = \App\Models\User::find(1)->lockForUpdate();
                sleep(60);
                $model->point = 100000;
                $model->save();
            } else {
                $model = \App\Models\User::find(1);
                $model->point = 999;
                $model->save();
            }

            return $model;
        }));
}

i try to test in 2 browser, browser 1 user logged in and browser 2 not logged in, browser 1 hit refresh, then there will lockforupdate and sleep 60 seconds before update

in the 60 seconds, i go browser 2 and hit refresh, however the record is not locked, i check phpmyadmin and the record is updated(within the 60 seconds lock trigger by browser 1)

but after 60 seconds, the record has been modified again by browser 1(Point 100000)

so am i misunderstanding the lockforupdate is use for?or i test it incorrectly?

what i expected is the row shouldn't be modified by browser 2 in the first 60 seconds(blank page with loading favicon or error throw?)

http://ift.tt/1kxDahl

btw i confirmed the database is innodb



via Chebli Mohamed

Is laravel created_at and updated_at inverse?

Laravel Framework version 5.2.5

When I updated a record, update_at was not changed but created_at changed to the current timestamp.

Is this correct?

MariaDB [moon]> show columns from users;
+----------------+------------------+------+-----+---------------------+-----------------------------+
| Field          | Type             | Null | Key | Default             | Extra                       |
+----------------+------------------+------+-----+---------------------+-----------------------------+
| id             | int(10) unsigned | NO   | PRI | NULL                | auto_increment              |
| name           | varchar(255)     | NO   |     | NULL                |                             |
| email          | varchar(255)     | NO   | UNI | NULL                |                             |
| password       | varchar(60)      | NO   |     | NULL                |                             |
| remember_token | varchar(100)     | YES  |     | NULL                |                             |
| created_at     | timestamp        | NO   |     | CURRENT_TIMESTAMP   | on update CURRENT_TIMESTAMP |
| updated_at     | timestamp        | NO   |     | 0000-00-00 00:00:00 |                             |
+----------------+------------------+------+-----+---------------------+-----------------------------+
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password', 60);
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('users');
    }
}



via Chebli Mohamed

Laravel: Cannot use helper inside php shorthand array

PHP version 5.6. Code:

protected $siteServices = [
        1 => [
            'title' =>  'Consulting',
            'key'       =>  'service',
            'description'   =>  '',
            'file'  =>  asset('assets/img/sample/image1.jpg'), // throws error on this line
        ],
];

Error: PHP Parse error: syntax error, unexpected '(', expecting ']'

What the hell?



via Chebli Mohamed