jeudi 27 octobre 2016

Laravel model "start" date attribute being changed

I have a controller which is updating a model through a request object. It looks

$save_series = Series::where('id','=',$request->input('data.item.id'))->with('booking')->first();
$save_series->name              = $request->input('data.item.name');
$save_series->color                 = str_replace('#', '', $request->input('data.item.color'));
$save_series->production_company    = $request->input('data.item.production_company');
$save_series->booking->start        = $request->input('data.item.booking.start');
$save_series->booking->end          = $request->input('data.item.booking.end');
$save_series->booking->save();
$save_series->save();               

When I save this the related "booking " object is updated. If the "end" date attribute is changed, then the "start" attribute's time is set to the current time; this shouldn't be the case! It seems to be ignoring the parsed $request start time completely.

On the related model to the booking I have put a setter mutator to see if the issue resides before that point - the date is being parsed correctly, yet once it hits the database it has changed. My setting (just for this test) looks like this:

public function setStartAttribute($time) {
    error_log(":::::::::::TEST BELOW:");
    error_log($time);
    return $time;
}

The error log result is:

PHP message: :::::::::::TEST BELOW:
PHP message: 2016-10-27 00:00:00" 

Yet the database field of "start" for this record reads:

2016-10-27 13:07:53

Please can someone explain what on earth is happening here; I'm completely and utterly lost!



via Chebli Mohamed

TokenMismatchException in VerifyCsrfToken.php line 67 only on live server

I'm getting this error when I try to use auth in Laravel 5.2. That had happened after moving to live server. On my local server everything works fine.

Token inside form and is Session:token() are the same.

UPD: I put dd($request) in laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php

and the _token value NOT matches _token input that is in form.

I tried:

  • Disable CSRF for auth routes, added routes in except array in Midd/VerifyCsrfToken.php.
    • Set up 777 rights to /storage /bootstrap folders.
    • Used {!! csrf_field() !!} and name="_token" value="">.
    • Changed domain in config/session.php.
    • php artisan key:generate.
    • Re-installed Auth. Also routes where I have middleware = auth.basic I'm getting "Invalid credentials" even without asking to log in at first.

On my local server it works fine.

Thanks



via Chebli Mohamed

Sending Variables to Word Document Laravel

There is any way of sending variables to a word document, rename it and make it downloadable from an application in laravel.



via Chebli Mohamed

POST 500 (Internal Server Error) Ajax

I want to send post request with ajax to controller in laravel. The ajax request send two input arguments and I want controller to find the column in the database with the first argument and then to set the name attribute with the second input argument. But I have this error message in console 500 (Internal Server Error).

Ajax function:

var $emailInput = $('input[name=eemail]').val();
var $finduser = $('[name=userName]').val();

$.ajax({
       type:"POST",
       url:'/code/task1/public/editUserAdmin',

       data: {
          'emailInput' : $emailInput,
           'finduser' : $finduser,
           },
          success:function(data){

       //  $("#editEmail").attr("readonly", true);
       //  $("#editEmail").val(data[0].name);

           alert("OK");
           }

   });

Route:

Route::post('/editUserAdmin', 'usersController@editUserAdmin');

Controller function:

$findUserInput = $request->input('finduser');
        $user = User::where('name',$findUserInput)->first();


         if(!$user){
            return response()->json(['status'=>false,'Description' => 'User could not be found.']);
        }
            //$user->name = $request->input('nameInput');
            $user->email = $request->input('emailInput');

            $user->save();
}

And also i import csrf everywhere because last time when I was making AJAX call i have problem with this csrf and the following code has fixed my problem, but now is not working.

<meta name="csrf-token" content="">

 $.ajaxSetup({
                headers:{
                    'X-CSRF-TOKEN' : $('meta[name="csft-token"]').attr('content')
                }
            });  

        $.ajaxSetup({
                   headers: {
                    'X-CSRF-TOKEN': $('[name="_token"]').val()
                }
            });

and this 
<h3 class="media-heading" name="userName"></h3>
<input type="hidden" name="_token" value="">
<input type="text" class="form-control paddingzero" class=text-center" readonly value="Name Name">
<input type="text" class="form-control paddingzero" class=text-center" name="eemail" id="editEmail" readonly value="">

Any idea?



via Chebli Mohamed

changing the parameters in authentication Laravel 5.3 with Hesto multi Auth

I wan't to change the login parameters in authentication. I'm using the Hesto Multi Auth package.

By default Hesto package gives a multi authentication with email and a password. Instead what i wan't to do is change it to a local identity number and the password.

Hesto_Package



via Chebli Mohamed

cannot create cache directory on mac in laravel 5.3

After i installed composer in mac os sierra then installed laravel framework 5.3, i cannot create cache directory or my directory is not writable, Proceeding without cache ( below detail error when installing laravel framework )

Please give me advise how to fix my problem, cause i'm newbie using mac

Thanks,

problem picture



via Chebli Mohamed

Codeception for Laravel 5: really interesting?

Codeception had a real appreciation on Laravel 4 by proposing an architecture of acceptances tests easier and complete

But when is it for Laravel 5?

When I see that Laravel 5 is capable of this test

public function testBasicExample()
{
    $this->visit('/')
         ->click('About Us')
         ->seePageIs('/about-us');
}

I wonder if codeception is always interesting for Laravel 5 ?



via Chebli Mohamed