jeudi 1 octobre 2015

How to set custom validation message in Laravel?

I want to show my own message instead of one provided by the framework, So I did the following but it is not making any difference and showing default messages.

$message = [];
    foreach($request->get('estimates') as $key => $val)
    {
        $rules['estimates.'.$key] = 'required|integer';
        $message['estimates.'.$key] = 'Incorrect value';
    }
    $rules['technical_information'] = 'required';
    $rules['project_risks'] = 'required';

    $this->validate($request, $rules,$message);



via Chebli Mohamed

Accessing env values in page Javascript in Laravel 5.1

I cannot find how to achieve this. I am looking to access an env value in a page's javascript in Laravel 5.1. Any help is appreciated!

I have tried the following without success:

var AppImagePath = "<?php echo {!! env('APP_IMG_PATH') !!}?>";

var AppImagePath = {!! env('APP_IMG_PATH') !!};



via Chebli Mohamed

ErrorException in Grammar.php line 39: Array to string conversion

This is my store function in CategorieController.php

public function store(Request $request) {
  Categorie::create([
  'name'=>$request['name'],
  ]);
  return redirect::to('/categorie');
}

and this is what I have in my model Categorie.php

class Categorie extends Model { 
  protected $table =['categories'];
  protected $fillable=['name'];
}

but when I try to save my categorie into database I get this error:

ErrorException in Grammar.php line 39: Array to string conversion



via Chebli Mohamed

Laravel - Using allfiles gives back empty array

I've been using laravel for nearly all my projects and I've came across a problem when trying to list all files in a directory.

Here is my code below:

            $directory = ("upload/"."$username->username");

        $scanned_directory = storage::allfiles($directory);

So as you can see First line is the directory which is in Upload followed by the username of the account.

The second line is meant to scan this directory and list only files. Sadly it always gives me back an empty array. Using Scandir() here works... But it gives me folders which I'm not wanting.

So... Any tips? I checked the API and I really can't see what is wrong here :(



via Chebli Mohamed

Laravel 5.1 doesn't allow you to pass in url params (is there configuration)

Consider the following test:

public function it_should_contain_a_list_of_investors_who_belong_to_one_or_more_investment() {
    $this->createInvestment();

    $investor = factory(User::class)->create([
        'role_id' => 4
    ]);

    $response = $this->actingAs($investor)
                     ->call('GET', 'api/v1/investors?include=investments');

    dd(json_decode($response->getContent()));
    $this->assertNotEmpty(json_decode($response->getContent()));
}

Now consider the following action this test is calling:

public function getAllInvestorsForCompany($slug)
{
    $users = $this->investorEntity->usersForCompany($slug);

    $resource = new Collection($users, new InvestorTransformer, 'investor');
    dd($_GET);
    if (isset($_GET['include'])) {
        $usersData = $this->manager->parseIncludes($_GET['include'])->createData($resource)->toArray();
    } else {
        $usersData = $this->manager->createData($resource)->toArray();
    }

    return response()->json($usersData);
}

Note the dd, the $_GET returns []

Lets do the same test in the browser:

array:1 [▼
  "include" => "investments.offering.company"
]

Ok so in the browser I get back investments.offering.company, because that is what I am passing in as the ?include= But in the test its like laravel ignores the ?include and moves on.

is this a default behaviour of laravel 5.1 tests and if so how do I shut it off?



via Chebli Mohamed

Laravel 5.1 - artisan make command

in Laravel 4.2 by using JeffreyWay/Laravel-4-Generators we could use

php artisan generate:view my-view

to create a view named my-view.blade.php.

Now in Laravel 5.1 what we should use to generate a view?

php artisan make:???



via Chebli Mohamed

How can I create select option in laravel

How can I create option in my blade view ?

This is in my controller

$user = DB::table('user')->whereIn('status_id',[1,2]) ->get();

In my view I want like this

<select name="myusers">
   <option value="{{ user->id }}">{{$user->name}})</option>
   <option value="{{ user->id }}">{{$user->name}})</option>
   <option value="{{ user->id }}">{{$user->name}})</option>
   <option value="{{ user->id }}">{{$user->name}})</option>
  
 
  
  </select>


via Chebli Mohamed