mardi 29 mars 2016

In Laravel 5, migration to drop composed unique key doesn't work

Trying to make a migration to drop composed unique key fails without errors.

I've created a migration with php artisan make:migration and edited the code. So I have this

public function up()
{
    Schema::table('ques_trilha_itens', function (Blueprint $table) {
        $table->dropUnique('trilha_itens_trilha_id_questao_id_unique');
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::table('ques_trilha_itens', function (Blueprint $table) {
        $table->unique(['trilha_id', 'questao_id']);
    });
}

The string 'trilha_itens_trilha_id_questao_id_unique' is the one that is displayed as the composed unique key in MySQL. So I think that string is to be used do drop the two composed keys.

But when running php artisan migrate, nothing happens, no error messages, and the migration is not executed.

I tried substitute the string in dropUnique to give the table's name as the first term ('ques_trilha_itens_trilha_id_questao_id_unique') and nothing.

Is something I'm missing?



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

Uncaught exception 'ReflectionException' with message 'Class App\Console\Kernel does not exist'

I never have any problem running composer install

But this morning, I ran into this error :

PHP Fatal error:  Uncaught exception 'ReflectionException' with message 'Class App\Console\Kernel does not exist' in /usr/share/nginx/ssc-portal/vendor/laravel/framework/src/Illuminate/Container/Container.php:741
Stack trace:
#0 /usr/share/nginx/ssc-portal/vendor/laravel/framework/src/Illuminate/Container/Container.php(741): ReflectionClass->__construct('App\\Console\\Ker...')
#1 /usr/share/nginx/ssc-portal/vendor/laravel/framework/src/Illuminate/Container/Container.php(631): Illuminate\Container\Container->build('App\\Console\\Ker...', Array)
#2 /usr/share/nginx/ssc-portal/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(674): Illuminate\Container\Container->make('App\\Console\\Ker...', Array)
#3 /usr/share/nginx/ssc-portal/vendor/laravel/framework/src/Illuminate/Container/Container.php(220): Illuminate\Foundation\Application->make('App\\Console\\Ker...', Array)
#4 /usr/share/nginx/ssc-portal/vendor/laravel/framework/src/Illuminate/Container/Container.php(738): Illuminate\Container\Container->Illuminate\Cont in /usr/share/nginx/ssc-portal/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 741


Here is my composer.json

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.1.*",
        "illuminate/html": "^5.0",
        "laracasts/utilities": "~2.0",
        "barryvdh/laravel-debugbar": "^2.0",
        "sammyk/laravel-facebook-sdk": "~3.0"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~4.0",
        "phpspec/phpspec": "~2.1"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "App/",
            "Helpers\\": "App/Helpers/"
        },
        "files": ["app/Helper.php"]
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-install-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "pre-update-cmd": [
        ],
        "post-update-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-root-package-install": [
            "php -r \"copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ]
    },
    "config": {
        "preferred-install": "dist"
    }
}


Did I do anything wrong ? Did I forget to run any commands ?

Any hints / suggestions on this will be much appreciated !



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

How to add a new exception handler to Laravel without disable the default one?

I'm using Sentry to keep tracking of exceptions from a Laravel application.

Sentry's docs say I should use the following code in my application bootstrap to setup the client:

$app->configureMonologUsing(function($monolog) {
    $client = new Raven_Client('your dsn');
    $handler = new Monolog\Handler\RavenHandler($client);
    $handler->setFormatter(new Monolog\Formatter\LineFormatter("%message% %context% %extra%\n"));
    $monolog->pushHandler($handler);
});

And that works fine!

The side effect is that Laravel's default exception handler, which writes the exceptions to the file at /storage/logs/laravel.log, stopped to work after adding the new exception handler.

How can I keep both handlers?



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

Ignore field in select Laravel Eloquent

Consider these models:

Flight Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Flight extends Model
{
  /**
   * The attributes that are mass assignable.
   *
   * @var array
   */
  protected $fillable =
  [
      'userID'
  ];    

  public function user()
  {
    return $this->belongsTo('App\User', 'userID');
  }
}

User Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class User extends Model
{
  /**
   * The attributes that are mass assignable.
   *
   * @var array
   */
  protected $fillable =
  [
      'userID', 'username', 'address'
  ];    
}   

I want to skip a column when I'm trying to use eager loading. I just want to know if something like IGNORE_FIELD FUNCTION exists, so I can do something like this:

$flightUser = Flight::with(['user', function ($q)
{
    $q->ignoreField('user.address');
}])

I know I could push the address field into the hidden array inside the User Model,

protected $hidden = ['address'];

or do the $q->select('fields') and not including the address field, but my real doubt is whether laravel has a function like the one I typed above.

NOTE

I know one field isn't that big of a deal. But my question is a simplified version of my real problem.



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

RedisStore Call to a member function get() on null

Getting this strange error when trying to run Sessions through Redis. Other drivers like database and file work fine. There is no further stack trace for me to track from where it is originating.

FatalErrorException in RedisStore.php line 54: 
Call to a member function get() on null

Please guide.



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

Can't access to a specfic field in JSON, saying undefined in javascript

I have a project in Laravel + socket.io , I need to access a specific field in the json being broadcasted. Here is the code.

socket.js

redis.on('message', function(channel, message) {
    message = JSON.parse(message);
    io.emit(channel + ':' + message.event,message.data); 
});

In my client socket, I have this.

socket.on("comment-channel:App\\Events\\CommentEvent", function(message){
        alert(message.data);
 });

then this will successfully, alert this.

[{
    "id": 136,
    "content": "dffsadf",
    "user_id": "1",
    "task_id": "33",
    "created_at": "2016-03-29 10:47:19",
    "user": {
        "id": 1,
        "first_name": "Hulk",
        "last_name": "Hogan",
        "username": "",
        "email": " hulhogan@yahoo.com",
        "company_id": "1",
        "role_id": "0",
        "photo": "\/assets\/apps\/img\/photos\/lvrv5VOGRskwPHvFVakp.jpeg",
        "position": "asdfsadf",
        "phone": "+75843857834",
        "city": "",
        "country": "Singapore",
        "timezone": "",
        "created_at": "2016-03-10 04:16:24",
        "updated_at": "2016-03-10 07:54:12",
        "deleted_at": null
    }
}]

Then when I try this

alert(message.data.task_id);

or

alert(message.data['task_id']);

I get 'undefined'..

How can I access, the task_id?Thank You!!!!



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

Laravel Eloquent: Return a value which is a sum() of a hasMany() with a constraint on a hasManyThrough()

I have three tables: PurchaseOrders, PurchaseOrderDetails, and Inventory.

Each PurchaseOrder has many PurchaseOrderDetails. Each Inventory item has many PurchaseOrder "through" a match of the SKU on PurchaseOrderDetails.

If I have the SKU, I want to do a sum of all PurchaseOrderDetails.OnOrder WHERE the parent PurchaseOrder has a NULL PurchaseOrder.ClosedDate.

How can I add this to my model so I can call App\Inventory::first()->OnOrder? I can get all the PurchaseOrders using:

public function OnOrder() {
    return $this->hasManyThrough(PurchaseOrder::class, PurchaseOrderDetail::class, 'LocalSKU', 'PONumber')->whereNull('PurchaseOrders.DateClosed');
}

I'm not sure how to break that down just to the PurchaseOrderDetails and sum up the OnOrder only where the SKU matches my original Inventory item.



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