vendredi 1 février 2019

Postgresql offset - insert rows with ids into middle of table

Using Laravel 5.1 and PostgreSQL, by necessity, I need to insert rows in the middle of the table.

The ids are primary keys, but are not autoincremented. Instead, the ids are set in the loaded spreadsheet, which map to other values.

Before I insert, I was thinking I could pre-offset the ids then insert. The problem with this is, offsetting row id 2 to id 3 obviously will throw the following error because id 3 already exists:

duplicate key value violates unique constraint

Question: I'm looking to ignore the pkey constraint while I offset the IDs.

Update Query:

update table1 as t1
set id = id + 1
where id >= 2;

table1

id | str_a
----------
1    a
2    b
3    c

table1 Modified: first offset

id | str_a
----------
1    a
3    b <--- offset id by +1
4    c <--- offset id by +1

table1 Modified: Inserted {id: 2, str_a: 'hello world'}

id | str_a
----------
1    a
2    hello world <--- inserted
3    b
4    c

table1_table2

table1_id | table2_id
--------------------
1             1
2             2
3             3

table1_table2 Modified: After insert

table1_id | table2_id
--------------------
1             1
2             null            
3 <- offset   2 <- table2_id 2 now belongs to offset table1_id 3
4 <- offset   3 <- table2_id 3 now belongs to offset table1_id 4

table2

id | str_b
----------
1    d
2    e
3    f



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

Laravel 5 : test artisan migrate with path

I need a little help please :

With Laravel migrations, I like to put the migration in subfolder.

in a testing class, this works :

$this->artisan('migrate:fresh');

But, this does not work :

$this->artisan('migrate:fresh --path=/database/migrations/v1');

Do you have the solution please to specify the path with the tests?

Thank you.



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

Laravel get image from S3 instead of local

I have a Laravel 5 app which was previously storing images locally. I have now modified it so that images are stored on an S3 server, I previously retrieved the local images like this...

$image_contents = Storage::get('myimages/logos/' . $image->filename);

Now I have moved to S3 storage, how can I instead get the image from the S3 bucket?



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

Chrome Keep Redirecting on a none Private Windows

I have a Laravel site that use to be able to load fine on my local Mac OS Mojave.

bheng.test

Now, when I tried to go to bheng.test, it kept redirecting to https://www.bunlongheng.com

But when I open it up in private browser, it seems to stay

/etc/hosts

127.0.0.1   bheng.test
127.0.0.1   local.test
127.0.0.1   resume.test


vhost

<VirtualHost *:80 >
    ServerName bheng.test
    VirtualDocumentRoot "/Users/bheng/Sites/bheng/public"
    UseCanonicalName Off
</VirtualHost>


enter image description here

I reset my Chrome caches, and still seeing it.

Why is that? Did someone else experience this too ?

Did I do anything wrong ?



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

Laravel 5.7 guard and middleware are not working


laravel Guard or middleware is not working .
my admin panel is always visiable in auth or non-auth.
i don't understand , what is the problem ?

Route:

Route::get('/admin', 'admin\adminController@index')->middleware('auth:admin');
    Route::get('/admin-login', 'auth\adminLoginController@index');
    Route::post('/admin-login', 'auth\adminLoginController@login')->name('admin.login.submit');

my controller's code : auth/adminLoginController

namespace App\Http\Controllers\auth;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Auth;

class adminLoginController extends Controller
{
    function __construct()
    {
        $this->middleware('guest:admin');
    }

    public function index()
    {
        return view('auth.admin-login');
    }

public function login(Request $request) {

        // Validate Data...
        $this->Validate($request,[
            'email'=>'required|email',
            'password'=>'required|min:6'
        ]);

   // checking...
  if(Auth::guard('admin')->attempt(['email' => $request->email, 'password' => $request->password], false, false)) {
     return redirect('/admin');
  } else {
    return redirect()->back()->with('message', 'Invalid Information');
 }
}
}

If i delete __construct() , then i can visit admin log-in page , otherwise i cannot go in !!

my code of auth.php :


Guards :

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],
    'api' => [
        'driver' => 'token',
        'provider' => 'users',
    ],

    'admin' => [
        'driver' => 'session',
        'provider' => 'admins',
    ],

    'admin-api' => [
        'driver' => 'token',
        'provider' => 'admins',
    ],

],


Providers :

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => App\User::class,
    ],

    'admins' => [
        'driver' => 'eloquent',
        'model' => App\admin::class,
    ],
],

my adminControllers code :
admin is always visiable in auth or without auth

namespace App\Http\Controllers\admin;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\User;

class adminController extends Controller
{
    public function index()
    {
        $user = User::all();
        $maleuser = User::where('gender','male')->get();
        $femaleuser = User::where('gender','female')->get();
        return view('admin/index')
                ->with('users',$user)
                ->with('maleusers',$maleuser)
                ->with('femaleusers',$femaleuser);
    }
}

Iam tried for solved issu . Iam not a expert developer . please help me !!



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

Laravel VueJS obtain data of parent model

I am trying to obtain a relationship value in vue. I have a simple relationship setup. A User can have many Reports and a Report belongs to a User. A User is able to create a Report. When they visit the reports page to see all their reports, the following function is called

public function index()
{
    $user_id = Auth::user()->id;
    return Report::latest()->where('user_id', $user_id)->paginate(20);
}

So it basically retrieves all reports that matches the logged in user id.

Within my view, this is what calls the above function

<script>
    export default {
        data() {
            return {
                reports: {}
            }
        },
        methods: {
            loadFiles() {
                axios.get("api/report").then(({ data }) => (this.reports = data));
            }
        },
        created() {
            this.loadFiles();
            Fire.$on('AfterCreate',() => {
                this.loadFiles();
            });
        }
    }
</script>

I am then displaying a users reports using a loop

<tr v-for="report in reports.data" :key="report.id">
    <td></td>
    <td></td>
</tr>

So the above works without any issues. What I was wondering is how I can actually obtain the users name from the report model? So instead of report.user_id, I would need something like report.user_id.name where name is a field within the users table. Obviously this does not work, so I was wondering if it was possible. I know how to get child data, but never really worked on getting parent data

Thanks



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

Webpack: bundle splitting across html pages vs code splitting across client side routes

Are there chunk size / loading time implications in choosing between:

  • Splitting a client side application into multiple bundles and serving them across different html pages (i.e. server side routing /about => about.html => about.bundle.js, etc) (this doesn't mean code splitting can't still be used on sub pages, e.g. admin/dashboard, admin/reports).

  • Serving a single client side application that uses code splitting across client-side routes.

And would the significance of chunk size / loading time most likely be eclipsed by architectural considerations such as:

  • The need/desire to share/isolate state across different routes

  • Overhead of abstracting app initialization code so that it can run in each bundle vs possibility to optimise initialization code per app bundle.

?

In general, why would you choose one approach over the other?



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