jeudi 26 novembre 2015

Laravel5 - Non-static method should not be called statically

I don't know what is this error. Please someone give me some explaination

on my UserController.php

class UserController extends Controller {
    public function viewCard($card_id) {
        return Tag::test($card_id);
    }
}

and on my model Tag.php

class Tag extends Model {
    public function test($card_id){
        return DB::SELECT(DB::RAW("SELECT name FROM tagmap tm, tags t WHERE t.id = tm.tag_id AND tm.card_id = :card_id"), ['card_id'=>$card_id]);
    }
}

i don't know where it fails, where I do wrong...



via Chebli Mohamed

Laravel 5 Route with multiple ID’s

I would like to pass two sets of ID’s into a route.

The first ID is that of the authenticated user so for example 3 and the second is that of a candidate.

So what I would like it to do is: vault/3/candidates/120

Here is the route I want to have:

Route::get('vault/{id}/candidates/{id}', 'CandidateController@centreCandidatesShow');

Using:

ublic function centreCandidatesShow($id)
{
    $candidate = Candidate::with('qualification')->find($id);

    return view('vault.show', compact('candidate'));
}

Could someone let me know if this is even possible and if so how?

I’m sorry if this question sounds stupid or is not even possible. I’m still very new to this.

Many thanks.



via Chebli Mohamed

Create Conditional Page View on Laravel by User Type

Does anyone know how to get this done? I'm trying to create a condition in Laravel's route. That if a type of user(example: Admin), the Dashboard page will be different from other types of user(example: Client).

See image here ->http://ift.tt/1lLSqIy

Noticed: They should go in the same URL domain.com/dashboard. The page that will be rendered to the view must reflect to the type of user that's login.

Idea, anyone? thank you so much!!



via Chebli Mohamed

Laravel 5 / L5: Set number of attempts when pushing job to a queue using Database connection

I have setup the Queue system in L5 using the Databse connection and after i run the migration I have two tables in my DB failed_jobs and jobs. Everything is working fine so far but when the pushed operation failed its keep going and trying to process the operation and did not delete the job on fail or inserted on failed_jobs

 Queue::push(function($job) use ($id)
 {
     Account::delete($id);

     $job->delete();
 });

In the above example how can I set number of attempts to try if not success and then insert into failed_jobs.

I know this can be done using

php artisan queue:listen --tries=3

But I want the same using the Closures as I have different cases



via Chebli Mohamed

Unable to install laravel 5 on windows via composer

I am trying to get started with laravel on windows and here is the command I tried:

rahul@rahulserver MINGW64 /d/PhpIdeaProjects/LaravelLearning $ composer create-project laravel/laravel learning-laravel-5

Here is the output I get:

Installing laravel/laravel (v5.0.22)
  - Installing laravel/laravel (v5.0.22)
    Loading from cache

Created project in learning-laravel-5
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for danielstjules/stringy 1.9.0 -> satisfiable by danielstjules/stringy[1.9.0].
    - danielstjules/stringy 1.9.0 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
  Problem 2
    - Installation request for laravel/framework v5.0.16 -> satisfiable by laravel/framework[v5.0.16].
    - laravel/framework v5.0.16 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.

So how shall I move on and have it working?



via Chebli Mohamed

Passing an id to other controller

$job->created_by = $input['created_by'];

I want to pass user id in this array which is in other table what should I do?

The field is a foreign key.

When I run this it throws an exception

SQLSTATE[23000]: Integrity constraint violation: 1452
     Cannot add or update a child row: a foreign key constraint fails 
     (`freight`.`jobs`, CONSTRAINT `approved_by` FOREIGN KEY (`created_by`)
     REFERENCES `users` (`id`))

     (SQL: insert into `jobs`
           (`company_id`, `origin`, `commodity`, `destination`,
            `created_by`, `approved_by`, `date`, `carrier`, `consolidator`,
            `overseas_agt`, `prepaid_fob`, `free_time`, `wt_pcs`, 
            `updated_at`, `created_at`)
           values (2, , , , asdsadasdsad, asdsadasdsad, , , , , , , ,
                   2015-11-26 07:32:02, 2015-11-26 07:32:02)
     )



via Chebli Mohamed

mercredi 25 novembre 2015

laravel named routing for package

I have been working with laravel 5 for package development.So i created a package with composer as 'lakshmajim/testview'.

the I have cloned that package for testing by creating fresh laravel project

composer require lakshmajim/testview dev-master

then updated composer.json main file like this

"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "App\\": "app/",
        "lakshmajim\\testview\\": "vendor/lakshmajim/testview/src"   
    }
},

then i have done

composer dumpautoload 
composer update 
php artisan vendor:publish

My routes (php artisan route:list)

    +--------+----------+-----------------+-------------------------+------------+
|Domain|Method | URI              |Name| Action                                      | Middleware |
    +--------+----------+-----------------+------+----------+------------+
|     | GET|HEAD| /              |     | Closure                       
|     | GET|HEAD| accessurl/{str}|     | lakshmajim\testview\TestviewController@index | |    
|     | GET|HEAD| hi             |     | App\Http\Controllers\Controller@e            |            |

When I tried to access http://localhost:8000/accessurl/any%20parameter%20here it works fine and shows result.

my controller file

use Redirect;

class Controller extends BaseController
{ 
        public function e()
        {
            $url='accessurl/strtestpackage';
            return Redirect::route($url);
        }
}

The problem is when I 'm trying to access package route form controller it shows following error

`**InvalidArgumentException in UrlGenerator.php line 296: Route [accessurl/str] not defined**`.

QUESTION How can I able to access named route present in vendor directory form controller? (How can I use vendor/lakshmajim/testview/src/routes.php file from app/Http/Controllers/Controller.php?)

Thanks.



via Chebli Mohamed