vendredi 1 février 2019

Constant expression contains invalid operations and Expression is not allowed as default value errors

I am using laravel 5.7 and I am trying to specify validation rules that when a user is updating their email the email must be unique BUT if its the same email for the current user ignore this rule. I am trying to pass the user id to the rule but its not working

The errors I am getting

Constant expression contains invalid operations

Expression is not allowed as default value

private $updateValidationRules =
 [
    'email' => ['required', 'string', 'email', 'max:255', 'unique:users,email,'."$this->id"],
    'name' => ['required', 'string', 'max:255'],
];

What am I doing wrong?



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2D0aoBx
via IFTTT

Laravel Google Map - Old form values not accepted

I am saving a longitude and latitude from Google Maps on form submit, I am trying to save the long and lat on validation fail using old like this..

map.setCenter({ lat:, lng: });

This is giving me...

InvalidValueError: setCenter: not a LatLng or LatLngLiteral: in property lat: not a number

When I examine the source I can see that the longitude and latitude are returned correctly, but Google Maps is not seeing them as a number.

Do I need to cast them as integers first?



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2Sm0rIf
via IFTTT

laravel 5.7 form setting route

I'm using laracel for first time and I have to seta form ,I have this form on the view

<html>
    <body>
        <h1>Hello</h1>

        <form method="POST" action="">
            <input type="text"/>
            <input type="submit" value="Enviar">
        </form>

        <script src=""></script>
        <script src=""></script>
    </body>
</html>

and this routes

Route::get('/', 'DateFormController@show');
Route::post('/date_process', 'DateFormController@process');

but Iget this error message

Route [date_process] not defined.

How I have to set the form action field to send to date_process function?



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2RBqEyc
via IFTTT

Get parameters from current url on View

i have a url with this structure:

http://localhost:8000/products?category=chairs&sort=name

And in my viw i inserted the links pagination:



But i need to append in the products links the parameters from my url using this method appends:



Has is showin the the example on the documentation, but how can i get has a array all the parameters from my current url that i show above?

The final result shoed include the category and the current sort.



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2MJkzyI
via IFTTT

Mockery not executing mock method

I have class Name Validator and it has a method forVote. This is my code.

public function test_should_set_default()
    {
        $this->mock = \Mockery::mock(Validator::class);
        $this->mock->shouldReceive('forVote')
            ->andReturnTrue();
        $this->app->instance(Validator::class,$this->mock);
        $factory = new Factory();
        $this->assertTrue($factory->setDefault());
    }

So Factory calls Processor which calls Validator. Now I want mock validator to run. But it calls the real method.

What am I doing wrong?



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2MIuzrS
via IFTTT

How to create different aliases by doing different queries in the same column in Laravel 5.7

I have a table in mysql where I store indexes, and I need to count a column of indices by bringing an alias for each count.

I tried the following code but it does not work, and as I am new to laravel, I'm not sure how I can build this query

$baralho = Baralho::baralho_all();
$data = Baralho::select(
    DB::raw('YEAR(data_entrada) as ano'),
    DB::raw('count(*) as inseridos, id_situacao'),
    DB::raw('count(*) as presos, id_situacao = 2'),
    DB::raw('count(*) as mortos, id_situacao = 3'),
    DB::raw('count(*) as retirados, id_situacao = 4')
)->groupBy('ano')->get();
$geral[] = ['Ano', 'Inseridos', 'Presos', 'Mortos', 'Retirados'];
foreach($data as $key => $value){
    $geral[++$key] = [$value->ano, $value->inseridos, $value->presos, $value->mortos, $value->retirados ];
}
dd($geral);

I need it to count the indexes and return a result for each alias, for example, if in the column id_situacao the index is 2 it counts all 2 indexes and brings me the result with the alias presos so that I can insert those results in the my array $geral[]



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2Bdthkq
via IFTTT

How to Compile Bootstrap Theme Scss Files in Laravel

I have bit knowledge about how to compile scss file using npm run dev. But now I have Bootstrap html theme folder where all assets files are included like scss and css . i am confused that is i have to @import all bootstrap theme folder scss files name in laravel app.scss file for compile or just copy Bootstrap theme folder scss files and paste on laravel assets/scss folder and run command npm run dev. please help thanks



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2S0Pnkd
via IFTTT