php – Laravel Boolean returns "1" / "0" instead of "true" / "false" in the query

I have a query that returns a Boolean field on my Laravel-developed REST API (by the way, I'm on an SQL server), and a few days ago it returned the value as true / false, but now it returns that Boolean field back value as string: "1" / "0".

Any idea what could it be?

That's my question:

return DB::table('dbo.visits as V')
        ->leftJoin('dbo.reports AS R', 'R.id_visit', '=', 'V.id')
        ->select('R.id','R.status'); // status is the boolean

Thank you in advance.

Validation – Customize the Socialite Laravel registration

Good night

I would like to use Socialite to log in to my system, but would like the user to be redirected to the registration page after the callback to completely fill in some information, such as the email Strava does not report.

If I then check the registry, I would like to do the following:
– If the e-mail exists, check if the entered password matches this e-mail and update the user (so far so good).
– If the e-mail exists and the password is not the same, return a warning to the user that this e-mail already exists (where I am stuck).
– If there is no e-mail, create a new registration … (also quietly).

protected function create(array $data)
{
    $user = User::where('email', $data('email'))->first();

    if ($user) {
        if (Hash::check($data('password'), $user->password)) {
            return User::updateOrCreate(
                (
                'email' => $data('email')
                ), (
                'name' => $data('name'),
                'phone' => $data('phone'),
                'cpf' => $data('cpf'),
                'sex' => $data('sex'),
                'weight' => $data('weight'),
                'avatar' => $data('avatar'),
                //'company_id' => $data('company_id'),
                //'coach_id' => $data('coach_id'),
                'strava_id' => $data('strava_id'),
                'strava_access_token' => $data('strava_access_token'),
                'strava_refresh_token' => $data('strava_refresh_token'),
                'strava_access_token_expires_at' => $data('strava_access_token_expires_at'),
            ));
        } else {
            // Como retornar a informação aqui????
        }
    } else {
        return User::create(
            (
            'email' => $data('email'),
            'password' => Hash::make($data('password')),
            'name' => $data('name'),
            'phone' => $data('phone'),
            'cpf' => $data('cpf'),
            'sex' => $data('sex'),
            'weight' => $data('weight'),
            'avatar' => $data('avatar'),
            //'company_id' => $data('company_id'),
            //'coach_id' => $data('coach_id'),
            'strava_id' => $data('strava_id'),
            'strava_access_token' => $data('strava_access_token'),
            'strava_refresh_token' => $data('strava_refresh_token'),
            'strava_access_token_expires_at' => $data('strava_access_token_expires_at'),
        ));
    }
}

Already turned the net and found nothing that worked …

laravel – Error in the unique rule during the update

I test the functionality of my request for data validation and encounter the following problem.

If I want to update a record, I have no problem. I have the problem that I want to give the same name to another record. In this case, the error "The name is already registered" should be output. However, instead of returning the error directly, the code explodes.

I enclose my codes to see if anyone has an idea of ​​what might happen.

controller

public function update(SucursalUpdate $request, $id)
{
    $sucursal = Sucursal::find($id);

    $sucursal->name = $request->name;
    $sucursal->estado = $request->estado;

    $sucursal->save();

    return redirect()->route('sucursales.index')->with('info','La sucursal fue actualizada correctamente');
}

Request BranchUpdate

public function rules()
{
    return (
        'name'      =>  'required',
        Rule::unique('sucursals')->ignore($this->id),
    );
}

Migration Sucursal's Table

public function up()
{
    Schema::create('sucursals', function (Blueprint $table) {
        $table->bigIncrements('id');

        $table->string('name')->unique();
        $table->boolean('estado')->defalut(1);

        $table->timestamps();
    });
}

Forward file

{Route::resource('sucursales', 'AdminSucursalController');
Route::get('sucursales/changeStatus/{id}', 'AdminSucursalController@changeStatus')->name('sucursales.changeStatus');}

how to solve Laravel 6.0 error upload file

I try to enter some data in the database
I can not enter some data into the database because I have this error
but I can log into my project with multi auth

and I got an error
Enter image description here

How can I fix this?

regulator

    nama_jurusan=$request->nama;
        $file=$request->file('fotohimpunan');
        if (!$file) {
            return redirect()->route('in.jurusan')->with('alert','foto harus diisi!');
        }
        $file_name=$file->getClientOriginalName();
        $path=public_path('/img');
        $file->move($path,$file_name);
        $jurusan->fotohimpunan='public/img/'.$file_name;
        $jurusan->status='disable';
        // dd($jurusan);
        $jurusan->save();


        return redirect()->route('in.jurusan');
    }
}

guard

 (
        'guard' => 'web',
        'passwords' => 'users',
    ),
    // Guard
    'guards' => (
        'web' => (
            'driver' => 'session',
            'provider' => 'users',
        ),
        'api' => (
            'driver' => 'token',
            'provider' => 'users',
        ),
        'admin' => (
          'driver' => 'session',
          'provider' => 'admin',
        ),
        'admin-api' => (
            'driver' => 'token',
            'provider' => 'admin',
        ),
        'panitia' => (
          'driver' => 'session',
          'provider' => 'panitia',
        ),
        'panitia-api' => (
            'driver' => 'token',
            'provider' => 'panitia',
        ),
        'mahasiswa' => (
          'driver' => 'session',
          'provider' => 'mahasiswa',
        ),
        'mahasiswa-api' => (
            'driver' => 'token',
            'provider' => 'mahasiswa',
        ),

    ),
    //  Providers
    'providers' => (
        'panitia' => (
            'driver' => 'eloquent',
            'model' => AppPanitia::class,
        ),
        'admin' => (
          'driver' => 'eloquent',
          'model' => AppAdmin::class,
        ),
        'mahasiswa' => (
          'driver' => 'eloquent',
          'model' => AppMahasiswa::class,
        ),

    ),
    // Password
    'passwords' => (
        'users' => (
            'provider' => 'users',
            'table' => 'password_resets',
            'expire' => 60,
        ),
    ),
);

How can I solve my problems, please help me
I can sign in with MultiAuth, but when I try to enter data, I get this error

laravel – Error updating the duplicate record

Based on the documentation of Laravel in your file Request You have to import if it does not exist the class Rule as follows:

use IlluminateValidationRule;

Once this is done, we will replace the use of unique from this class and indicate which parameters the URL He is the one who ignores the following:

Validator::make($sucursal, (
    'name' => (
        'required',
        Rule::unique('tabla')->ignore($sucursal->name)
    ),
));
  • Therefore, we state that we will apply a unique rule to the table users for example
  • But let us ignore, if there is a double name (in an update)since then unique first of all looks for a record with this value already exists (if we insert) and prevents a new record with the same value.

references

PHP – Laravel authentication with database user

Good morning community.

Ideas that help me to carry out the following experiment.

I need to change the Laravel authentication so that I can connect to the database using the credentials of the logged-on user.

I explain that at the time of login, the application will connect the database to a user to consult the user tables. Once the user is authenticated, the following queries and executions in the database are performed with the credentials of the logged-in user, because in addition to being registered in the database, he also has a homolog as a database user.

This to implement database level security. D. H., Not only the application, but also the database, indicates who can retrieve what and what procedures they can perform.

Thank you for your time, I will be attentive to your comments.


Note: The connection database is SQL Server 2017 and the version of Laravel 5.8

vue.js – Laravel + Vuejs: The POST method is not supported for this route: Import in table with Laravel Excel

Greetings I have a problem with Laravel. I would like to send an Excel file from my component created in Vuejs. I want to import this file into a spreadsheet with about 5Mb and 36 records. I'm using the LaravelExcel V.3 library, I'm using multipart / form data on my form and my route is POST type with the axios library. I appreciate your answers and contributions.

My component – FrontEnd


My component – Vuejs


My post route in Laravel

//Medicamentos (Catalogo)
Route::post('/actualizacatalogo','MedicamentoController@importarexcel');

My controller

public function importarexcel(Request $request)
    {

            Excel::import(new MedicamentoImport(),$request->file('file'));
            return back();

    }

Enter image description hereEnter image description here

laravel – MySQL, which data type should DateTime store when working with time zones?

I have an application to publish jobs. Users can select the start and end dates / end times for the time when the job goes live and expires.

Users who publish jobs can be located in any country, but most of them in the UK, so their start and end dates are in their local time. For the time being, however, I have explicitly stated this in order to simplify the application. All times are in the "Europe / London" time zone, but I would like to keep the framework in order to truly internationalize the app at a later date.

Note: I also store the user's time zone in a database column, but as mentioned above, for the time being, all users are located in "Europe / London" when viewing the data.

  1. The question is, will I convert this data to UTC before storing it in the database? Which data type is best for storing these data / times in mysql? DateTime or Timestamp?

  2. I've read a lot of posts about restrictions on using timestamps, such as: For example, the internal conversion of values ​​to UTC and the 2038 issue. Since I convert the dates in my application layer to UTC before saving, it makes sense to use a timestamp field because this conversion would be done twice. No, correct me if I'm wrong or it does not matter. When entered in a time stamp field as UTC, it is output in a time stamp field as UTC.

  3. If I perform a search, such as one of the following queries, to return all the live jobs, I must now convert all the data in that query to the Europe / London time zone.

For example, from:

SELECT jobs.*
 , TIMESTAMPDIFF(DAY, NOW(), jobs.end_dt) as days_remaining
FROM jobs
WHERE jobs.start_dt <= NOW() and jobs.end_dt >= NOW() 

To:

SELECT jobs.*
  , TIMESTAMPDIFF(DAY, CONVERT_TZ(now(),'UTC','Europe/London'), CONVERT_TZ(jobs.end_dt,'UTC','Europe/London')) as days_remaining
FROM jobs
WHERE CONVERT_TZ(jobs.start_dt,'UTC','Europe/London') <= CONVERT_TZ(now(),'UTC','Europe/London') AND CONVERT_TZ(jobs.end_dt,'UTC','Europe/London') >= CONVERT_TZ(now(),'UTC','Europe/London')

If you use timestamps as the data type, you need to know which time zone the current time zone is set for MySQL. MySQL converts TIMESTAMP values ​​from the current time zone in UTC to save and back from UTC to the current time zone for retrieval. (This does not occur with other types such as DATETIME.) By default, the current time zone for each connection is the time of the server. Maybe we need to set up our laravel mysql connection configuration as follows to make sure we do not get any wrong results:

  'UTC',


  // AND in config/database.php

 'connections' => (

  'mysql' => (
    //....
   'timezone'  => '+00:00', // set to UTC
  ),

Do you have any advice and considerations, tips and tricks?

Note: I originally posted this on SO, but no one seems to have any idea … Maybe because this is more of a design issue.

php – Unknown characters between each letter when reading the CSV uploaded to Laravel

I'm trying to upload a CSV file, read its contents, and import that data into a database, but apparently I get an error where an unknown character appears between each character.

This is my code:

    $file = $request->file('file');
    $fileName = $file->getRealPath();
    $file = fopen($fileName, "r");

    $i = 0;
    while (($column = fgetcsv($file, 10000, ";")) !== FALSE) {

        if ($i == 0){
            $i++;
            continue;
        }
        echo print_r($column);$i++;    
    }

    fclose($file);

I get that from print_r:

Enter image description here

Any ideas why it could be? I tried to open the CSV encoding UTF8 and UTF16, but I still have this problem.

Thank you in advance.

mysql – Is there a safety recommendation for laravel? The database has been hacked

My Laravel database was hacked for the second time. The hacker deleted all tables and a table threatens to delete if I have not sent Bitcoin. This is not a problem as I have a backup, but what can I do to prevent it? The first time I enabled the debugging mode in the .env file, I thought this might be the problem. After turning off debugging, I was still hacked. Am I missing something?

This is for Laravel 6. The first time I enabled the debugging mode in the .env file, so I thought this might be the problem. After turning off debugging, I was still hacked. Am I missing something?