laravel-shopify icon indicating copy to clipboard operation
laravel-shopify copied to clipboard

Posting and redirect

Open ihateonions-uk opened this issue 4 years ago • 8 comments

Hi all, hope someone can help me out here.

When I post my form and use return redirect()->tokenRedirect(... in my controller, the returned page errors with 'Trying to get property 'name' of non-object' for the Auth::user()->name.

Any ideas of what im missing or doing wrong would be much appreciated.

See here for the stack trace. https://flareapp.io/share/Rmr9DLd5

Thanks in advanced

ihateonions-uk avatar Jul 13 '21 17:07 ihateonions-uk

No issues for me at the moment.. I just tested with this:

Route::match(
    ['get', 'post'],
    '/orders',
    function (Request $request) {
        if ($request->getMethod()=== 'POST') {
            return Redirect::tokenRedirect('orders', ['notice' => ['message' => 'Posted!']]);
        }

        return view('orders', ['shop' => $request->user()]);
    })
    ->middleware(['verify.shopify'])
    ->name('orders');

With this:

@extends('shopify-app::layouts.default')

@section('content')
    <p>Hello {{ $shop->name }}</p>

    <form action="{{ route('orders') }}" method="post">
        @sessionToken
        <input type="text" name="test" value="test">
        <button type="submit">Submit</button>
    </form>
@endsection

And posting was successful. Is the route you're trying to hit, not behind verify.shopify?

gnikyt avatar Jul 13 '21 18:07 gnikyt

Thanks for the quick reply and your example. Yes it is behind the correct verify.shopify middleware, ive tried it in a route group and on its own an neither seem to work.

I have the correct {{@sessionToken}} on the form and the action goes to the post route.

This is from my web.php route

Route::get('email-builder', function () {return view('email-builder');})->middleware(['verify.shopify'])->name('email-builder');

Route::post('saveEmailTemplateDetails', "EmailTemplatesController@update")->name('saveEmailTemplateDetails')->middleware(['verify.shopify']);

And then in my function in the controller is the simple tokenRedirect return redirect()->tokenRedirect('email-builder');

I feel like im missing something really simple somewhere.

ihateonions-uk avatar Jul 13 '21 19:07 ihateonions-uk

Hmm alright.

gnikyt avatar Jul 14 '21 16:07 gnikyt

I have the same issue. I also use Inertia.js and not sure if that has something to do with it. Going to look more into it tomorrow and see if I can find something.

mattias avatar Jul 15 '21 14:07 mattias

@sessionToken

@osiset Can we have this piece of information in the Wiki please?

burfbari avatar Sep 08 '21 17:09 burfbari

@sessionToken

@osiset Can we have this piece of information in the Wiki please?

This please 🙏

LeafedFox avatar Oct 18 '21 08:10 LeafedFox

I can't redirect too. in version 16 this code was working:

return redirect('/')->with(['errors'=>'Please fill the basic required information first.']);

but in version 17 none of these codes work:

return redirect('/')->with(['errors'=>'Please fill the basic required information first.']);
return redirect()->tokenRedirect('dashboard')->with('shopDomain', Auth::user()->name);
return Redirect::tokenRedirect('dashboard', ['notice' => ['message' => 'Posted!']]);

samshahbazi avatar Nov 11 '21 08:11 samshahbazi

Hi guys,

Do we have any solutions for this issue?

PhongNguyen512 avatar Feb 01 '22 16:02 PhongNguyen512

This is a stale ticket now, so going to close but re-open if problem is still there.

Kyon147 avatar Oct 04 '22 18:10 Kyon147