Buy your loved one the ultimate gift. Lifetime gift certificates are $100 off.

splendidkeen

Experience

6,010

1 Best Reply Awards

  • Member Since 2 Months Ago
  • 24 Lessons Completed
  • 0 Favorites

13th December, 2017

splendidkeen started a new conversation Multiple Image Upload: Shifting Upload Behavior • 6 hours ago

Hello, I am facing some problems with uploading multiple pictures. Problem:

Sometimes...

  1. when I want to upload 3 pictures, it will upload only 2 of the 3 and name one equally to one of the 2 uploaded, so it has the same name within the DB.
  2. when I want to upload 2 pictures, it will store 2 records for only one picture within the DB.
  3. it stores/uploads 2 pictures I selected, correctly.

When I dd:

foreach ($request->images as $image) {             
    dd($request->images);
}

it correctly returns (without any deviation)

array:3 [▼
  0 => UploadedFile {#370 ▶}
  1 => UploadedFile {#371 ▶}
  2 => UploadedFile {#372 ▶}
]

Controller:

$this->validate($request, [

    'business_image'=> 'max:2048',
            
]);         
            
foreach ($request->images as $image) {
                        
                        $business = Auth::user();
                        $filename = time() . '.' . $image->getClientOriginalExtension();
                        $location = public_path('uploads/'. $filename );          
                        $image = Image::make($image->getRealPath());
                        $image->resize(812, null, function ($constraint){$constraint->aspectRatio();})->save($location);
                    $pictures[] = new Picture(['business_image' => $filename]);

                    }

                    $business->pictures()->saveMany($pictures);

Picture.php

public function business(){
        return $this->belongsTo(Business::class);
}

Business.php

public function pictures(){
          return $this->hasMany(Picture::class);
}

Pictures Table:

 Schema :: create ('pictures', function(Blueprint $table){
            $table->increments('id');
            $table->unsignedInteger('business_id'); // 
            $table->string('business_image')->default('default.jpg');
            $table->timestamps();
 });

Problem Assumptions:

a) Could $filename = time() . '.' . $image->getClientOriginalExtension(); be a problem, because the filename is stored by the upload time? When I add mt_rand() it still faces at least problem 1)

b) When I use 3 pictures with different extensions, it sometimes stores 2 different pictures with the same filename(time string) but different extension.

c) Maybe one image can't get through the size validation, but I also tested it with 2 pictures and sometimes they uploaded, sometimes they didn't.

Any suggestions?

9th December, 2017

splendidkeen left a reply on Pivot Table: If/elseif Statement Problem • 3 days ago

Update alreadyFollows() Method for this conversation:

public function alreadyFollows(Business $business){
        return $this->stores()->where('business_id', $business->id)->wherePivot('supported', true)->get();
    }

splendidkeen left a reply on Pivot Table: If/elseif Statement Problem • 3 days ago

@36864 Sorry for coming back

When I follow a business, it will display the unfollow button at every other business even though no relationship was made.

@if(!Auth::check())
                
                <button>Follow</button>

@elseif (Auth::user()->alreadyFollows($business)->isNotEmpty())

              <form action="{{ route('stores.delete', $business) }}" method="post">
                  <input type="submit" name="" value="Unfollow">
                  <input type="hidden" name="_token" value="{{ csrf_token() }}">
                </form>
          
@elseif (Auth::user()->alreadyFollows($business)->isEmpty())
                
                 <a href="{{ route('stores.add', $business) }}">Follow</a>
 @endif

User.php

 public function stores(){
       return $this->belongsToMany(Business::class, 'supporters', 'user_id', 'business_id')->withTimestamps(); 
}

public function alreadyFollows(Business $business){
        return $this->stores()->wherePivot('supported', true)->get();
}


Plus a relationship between one User and one Business can be stored multiple times, which it should not. Is there anything obvious ?

splendidkeen started a new conversation Pivot Table (Many-to-Many Relationship) If/elseif Problem • 4 days ago

Hello everybody, I am currently working on a simple follow functionality, but facing some important problems. At the $business view Users can use a follow or unfollow trait, but it always shows the Unfollow button, even though there might not be a relationship in the 'supporters' pivot table.

If the column 'supported' equals true, it should show the unfollow button.

When I follow a business, it will display the unfollow button at every other business even though no relationship was made.

@if(!Auth::check())
                
                <button>Follow</button>

@elseif (Auth::user()->alreadyFollows($business)->isNotEmpty())

              <form action="{{ route('stores.delete', $business) }}" method="post">
                  <input type="submit" name="" value="Unfollow">
                  <input type="hidden" name="_token" value="{{ csrf_token() }}">
                </form>
          
@elseif (Auth::user()->alreadyFollows($business)->isEmpty())
                
                 <a href="{{ route('stores.add', $business) }}">Follow</a>
 @endif

Business.php

public function users(){
        return $this->belongsToMany(User::class, 'supporters', 'business_id', 'user_id');
}

User.php

 public function stores(){
       return $this->belongsToMany(Business::class, 'supporters', 'user_id', 'business_id')->withTimestamps(); 
}

public function alreadyFollows(Business $business){
        return $this->stores()->wherePivot('supported', true)->get();
}

public function followStore(Business $business){
        $this->stores()->save($business, ['supported' => true]);
 }

The button functionality works, creates and deletes relationship, but the button is not dynamic based on the relationship records, and a relationship between one User and one Business can be stored multiple times, which it should not.

Any obvious problems?

splendidkeen left a reply on Pivot Table: If/elseif Statement Problem • 4 days ago

Sorry, I am facing a problem @36864

When I follow a business, it will display the unfollow button at every other business even though no relationship was made.

@elseif (Auth::user()->alreadyFollows($business)->isNotEmpty())

              <form action="{{ route('stores.delete', $business) }}" method="post">
                  <input type="submit" name="" value="Unfollow">
                  <input type="hidden" name="_token" value="{{ csrf_token() }}">
                </form>
          
@elseif (Auth::user()->alreadyFollows($business)->isEmpty())
                
                 <a href="{{ route('stores.add', $business) }}">Follow</a>
 @endif

User.php

 public function alreadyFollows(Business $business){
        return $this->stores()->wherePivot('trusted', 1)->get();
}

splendidkeen left a reply on How To Adjust A Foreach Loop To List Content Horizontal? • 4 days ago

Makes sense, thank you @shanedara

splendidkeen started a new conversation How To Adjust A Foreach Loop To List Content Horizontal? • 4 days ago

Hello everybody,

I am working on listing four products in a row, until every business related product is listed. With the foreach loop below, it will list the same product 4 times in a row, and each product has a new row.

How would it be possible to change it, so every col-sm-3 the next product will be parsed in?

@foreach($business->products as $product)
<div>
  <div class="row">
    <div class="col-sm-3">
     <img src="/uploads/{{ $product->pictures->first()->product_image }}">
      <p>{{ $product->title }}, {{ $product->price }}€</p>
    </div>
    <div class="col-sm-3">
     <img src="/uploads/{{ $product->pictures->first()->product_image }}">
      <p>{{ $product->title }}, {{ $product->price }}€</p>
    </div>
    <div class="col-sm-3">
     <img src="/uploads/{{ $product->pictures->first()->product_image }}">
      <p>{{ $product->title }}, {{ $product->price }}€</p>
    </div>
    <div class="col-sm-3">
     <img src="/uploads/{{ $product->pictures->first()->product_image }}">
      <p>{{ $product->title }}, {{ $product->price }}€</p>
    </div>
    
  </div>
</div>
@endforeach

7th December, 2017

splendidkeen left a reply on Pivot Table: If/elseif Statement Problem • 6 days ago

Will still not display the block. Thanks, anyway @36864

splendidkeen left a reply on Pivot Table: If/elseif Statement Problem • 6 days ago

This results in

0 => Business {#297 ▼
#relations: array:1 [▼
        "pivot" => Pivot {#297 ▼
          +parent: User {#298 ▶}
          #foreignKey: "user_id"
          #relatedKey: "business_id"
          #guarded: []
          #connection: "mysql"
          #table: "supporters"
          #primaryKey: "id"
          #keyType: "int"
          +incrementing: true
          #with: []
          #withCount: []
          #perPage: 15
          +exists: true
          +wasRecentlyCreated: false
          #attributes: array:2 [▼
            "user_id" => 1
            "business_id" => 12

@36864

splendidkeen left a reply on Pivot Table: If/elseif Statement Problem • 6 days ago

This will result in

Column not found: 1054 Unknown column 'supporters.1'

same for ('supported', true)

@36864

splendidkeen left a reply on Pivot Table: If/elseif Statement Problem • 6 days ago

@36864 Thanks

0 => Business {#297 ▼
#relations: array:1 [▼
        "pivot" => Pivot {#284 ▼
          +parent: User {#298 ▶}
          #foreignKey: "user_id"
          #relatedKey: "business_id"
          #guarded: []
          #connection: "mysql"
          #table: "supporters"
          #primaryKey: "id"
          #keyType: "int"
          +incrementing: true
          #with: []
          #withCount: []
          #perPage: 15
          +exists: true
          +wasRecentlyCreated: false
          #attributes: array:3 [▼
            "user_id" => 1
            "business_id" => 12
            "supported" => 1
          ]

splendidkeen left a reply on Pivot Table: If/elseif Statement Problem • 6 days ago

@36864 This will show me the array with the related business. So the problem is within the storeblock?

splendidkeen left a reply on Pivot Table: If/elseif Statement Problem • 6 days ago

@36864 Should I dump the $business ?

Controller

$user->stores()->wherePivot('supported')->get();

dump(?);

splendidkeen left a reply on Pivot Table: If/elseif Statement Problem • 6 days ago

Thanks again. It won't get a record, even though there is one, also no error displayed @36864

Is there another way to get the collection?

splendidkeen left a reply on Pivot Table: If/elseif Statement Problem • 6 days ago

I created this foreach statement to display the relationship, but it won't show the storeblock. Anything problematic with it? @36864 @sutherland

@foreach($user->stores()->wherePivot('supported', true) as $business)
    @include('user/partials/storeblock')
@endforeach

splendidkeen left a reply on Redirect To Log-in If It Is Not Authenticated • 6 days ago

@brayano You could structure it like so, with a signing.blade.php View, where you input the User credentials: First you get the signing View, then you post the signin, with your 's POST method

AuthController

public function getSignin(){
        return view ('auth.signin');
    }

public function postSignin(Request $request){
        //Validate form data
        $this -> validate ($request, [
            'email' => 'required',
            'password' => 'required',
        ]);


        // if successful, then redirect to their intended location
        if(Auth::attempt(['email' => $request->email, 'password' => $request->password], $request->remember)){
            return redirect()->route('your intended location');
        }
        // if unsuccessfull, then redirect back to the login with the form data
        return redirect()->back()->withInput($request->only('email', 'remember'))->with('info', 'Could not sign in with those details');
}

Route

Route::get('/login', [
    'uses' => '[email protected]', 
    'as' => 'auth.signin',
    'name' => 'login',
    'middleware' => ['guest'],
    ]);

Route::post('/login', [
    'uses' => '[email protected]',
    'name' => 'login',
    'middleware' => ['guest'],
    ]);

splendidkeen left a reply on Pivot Table: If/elseif Statement Problem • 6 days ago

Thank you, both, @sutherland & @36864

splendidkeen left a reply on Redirect To Log-in If It Is Not Authenticated • 6 days ago

Is this at your log-in view? @Brayano

// if unsuccessfull, then redirect back to the login with the form data
return redirect()->back()->withInput($request->only('email', 'remember'))->with('info', 'Could not sign in with those details');

splendidkeen started a new conversation Pivot Table: If/elseif Statement Problem • 6 days ago

Hello. I'm facing some problems with an if/elseif statement. At my view Users can use a simple follow or unfollow trait, but it always show the Unfollow button, even though there might not be a relation ship in the 'supporters' pivot table. If the column 'supported' equals true, it should show the unfollow button.

View

@if(!Auth::check())
                
               <button class="btn btn-primary">Follow</button>            

@elseif (Auth::user()->alreadyFollows($business))
                
                 <form action="{{ route('stores.delete', $business) }}" method="post">
                  <input type="submit" name="" value="Unfollow" class="btn btn-primary">
                  <input type="hidden" name="_token" value="{{ csrf_token() }}">
                </form>

@elseif (!Auth::user()->alreadyFollows($business))

                <a href="{{ route('stores.add', $business) }}" class="btn btn-primary">Follow</a>
@endif

User.php

 public function stores(){
       return $this->belongsToMany(Business::class, 'supporters', 'user_id', 'business_id'); 
}

public function alreadyFollows(Business $business){
        return $this->stores()->wherePivot('supported', true)->get();
}

The button functionality works, creates and deletes relationship, but the button is not dynamic based on the relationship records

So, it always shows the Unfollow button, event though no relationship is present. Anything obvious with the elseif combination?

Thank you

5th December, 2017

splendidkeen left a reply on Eloquent-Relationship With Pivot Table/ DB Error • 1 week ago

Sorry for coming back @tykus

I'm facing some problems with my if/elseif statement at the view:

@if(!Auth::check())
                
                <a href="{{route('auth.signup')}}"><button class="btn btn-primary">Follow</button></a>             

@elseif (Auth::user()->alreadyFollows($business))
                
                 <form action="{{ route('stores.delete', $business) }}" method="post">
                  <input type="submit" name="" value="Unfollow" class="btn btn-primary">
                  <input type="hidden" name="_token" value="{{ csrf_token() }}">
                </form>

@elseif (!Auth::user()->alreadyFollows($business))

                <a href="{{ route('stores.add', $business) }}" class="btn btn-primary">Follow</a>
@endif

public function alreadyFollows(Business $business){
        return $this->stores()->wherePivot('supported', true)->get();
}

It always shows the Unfollow button, event though no relationship is present. Anything obvious with the elseif combination?

4th December, 2017

splendidkeen left a reply on BadMethodCallException: Method Update Does Not Exist • 1 week ago

Understand, thanks @Snapey

splendidkeen left a reply on BadMethodCallException: Method Update Does Not Exist • 1 week ago

It finally worked with the POST method. @Snapey thank you so much, you are just great

splendidkeen left a reply on BadMethodCallException: Method Update Does Not Exist • 1 week ago

Route::put('/product/{product}', [
    'uses' => '[email protected]', 
    'as' => 'products.update',
    'middleware' => ['auth:partner'],
]);

@Snapey I changed it and tested it for both, put and patch

splendidkeen left a reply on BadMethodCallException: Method Update Does Not Exist • 1 week ago

Form

method="{{ method_field('PATCH') }}"
method="{{ method_field('PATCH') }}"

@Snapey Already tried it, this will return the same error with (array('PUT / PATCH')

splendidkeen left a reply on BadMethodCallException: Method Update Does Not Exist • 1 week ago

Thanks, again @Snapey Now it gets the Product edit correctly. When I push the button, it results in:

MethodNotAllowedHttpException. 
at RouteCollection->methodNotAllowed(array('POST'))
in RouteCollection.php (line 238)

Maybe because update action needs the verb: PUT/PATCH?

splendidkeen left a reply on BadMethodCallException: Method Update Does Not Exist • 1 week ago

@Snapey Sadly only the Url /product/{product} for the GET Route it lists both, the Url /product/{product}/edit and products.edit as the name

splendidkeen left a reply on BadMethodCallException: Method Update Does Not Exist • 1 week ago

@Snapey

Using: 5.4.33

and it lists the Post Route, but not the name.

splendidkeen left a reply on BadMethodCallException: Method Update Does Not Exist • 1 week ago

When I want to get the Product Edit, it returns

Route [products.update] not defined. 

referring to the form in edit.blade.php

splendidkeen left a reply on BadMethodCallException: Method Update Does Not Exist • 1 week ago

You are right @Snapey

<form class="form-vertical" role="form" action="/product/{product}" method="POST">

splendidkeen left a reply on BadMethodCallException: Method Update Does Not Exist • 1 week ago

@Snapey

Thanks, the Url is still a problem as it displays,

/products/%7Bproduct%7D

and now the POST method will again end up on the User Backend, even though I am logged in as a Business.

Looks like, this Route

// Product Route

Route::get('/products/{product}', [
    'uses' => '[email protected]', 
    'as' => 'products.show',
    
    ]);

is a problem, even though I structured the Business routes like so /product/{product}/edit & /product/{product} without the 's'?

splendidkeen left a reply on BadMethodCallException: Method Update Does Not Exist • 1 week ago

Thank you again @Snapey Updated the routes according to the Resource Controller Table

Route::get('/product/{product}/edit', [
    'uses' => '[email protected]', 
    'as' => 'products.edit',
    'name' => 'products.edit',
    'middleware' => ['auth:partner'],
    ]);

Route::post('/product/{product}', [
    'uses' => '[email protected]', 
    'name' => 'products.update',
    'middleware' => ['auth:partner'],
    ]);

It will again return the error: Method update does not exist: at Collection->__call('update', array(array('title' => 'Title Collection'.......

Controller:

$product = Product::findOrFail($id);
                $product->update([

                    'title' => $request->input('title'),
                    'brand' => $request->input('brand'),
                    'sku' => $request->input('sku'),
                    'description' => $request->input('description'),
                    'price' => $request->input('price'),
                    'availability' => $request->input('availability'),

                ]);

I am not sure, what the problem is, but could there be a potential of failure because my Users will access the products via this route:


// Product Route

Route::get('/products/{product}', [
    'uses' => '[email protected]', 
    'as' => 'products.show',
    
]);

splendidkeen left a reply on Product Creation With Variation (size) / Input Request • 1 week ago

Yes, I know that would work. Thank you @jdunsmore

splendidkeen left a reply on Product Creation With Variation (size) / Input Request • 1 week ago

Thanks @jdunsmore

At the moment I am creating them like so

$product = Auth::user()->products()->create([
            'business_id' => auth()->user()->id,
            'title' => $request->title,
            'brand' => $request->brand,
            'description' => $request->description,
            'price' => $request->price,
            'availability' => $request->availability,    
]);

So I am validating the inputs and then storing them into the products table as a new product. But, how could I manage it to have for example a size input, where they can push e.g. a +Button and add Sizes to the product

splendidkeen started a new conversation Product Creation With Variation (size) / Input Request • 1 week ago

Hello, I was asking myself how to let Users create products with adding different sizes to the product, they are creating.

Relation would be:

Product.php hasMany variations()
Variation.php belongsTo product()

Variations table

Schema :: create ('variations', function(Blueprint $table){
            $table->increments('id');
            $table->unsignedInteger('product_id'); 
            $table->string('size'),
        $table->string('qty'),
            $table->timestamps();

But I don't know how to create inputs, where they can add sizes with qty. to the product. Anyone knows how to do this or how the process would look like? Thank you

splendidkeen left a reply on BadMethodCallException: Method Update Does Not Exist • 1 week ago

Sorry for coming back @Snapey I might have found the problem.

When I dd($product) like so

$product = Auth::user()->products()->first();

dd($product);

it returns the correct product information and also updates the correct product (always the first one)

When I dd($product) like so

$product = Auth::user()->products()->findOrFail($id);

dd($product);

which returns a Collection of items[]

Both with Routes:

Route::get('/product/{product}/edit', [
    'uses' => '[email protected]', 
    'as' => 'partner.profile.editproduct',
    'middleware' => ['auth:partner'],
    ]);

Route::post('/edited', [
    'uses' => '[email protected]', 
    'middleware' => ['auth:partner'],
    ]);

But, when I change the POST Route like so

Route::post('/edited/{id}'

it ends up on my (User) system as a logged in User, with the info that this page could not be found, even though the Route is protected with the Partner guard.

1st December, 2017

splendidkeen left a reply on Eloquent-Relationship With Pivot Table/ DB Error • 1 week ago

@tykus sorry for coming back, seems like

public function alreadyFollows(){
        return $this->stores()->wherePivot('supported', true)->get();
}

doesn't work

Controller:

if(Auth::user()->alreadyFollows($business)){
            return redirect()
                ->route('partner.show', $business)
                ->with('info', 'Already following.');
        }

        Auth::user()->followStore($business);
        
        return redirect()->route('partner.show', $business)->with('info', 'Supported.');

When I try to view it, it won't show the correct button

 @if (Auth::user()->alreadyFollows($business))

                <form action="{{ route('stores.delete', $business) }}" method="post">
                  <input type="submit" name="" value="Unfollow">
                  <input type="hidden" name="_token" value="{{ csrf_token() }}">
                </form>


              @else 
         
                <a href="{{ route('stores.add', $business) }}">Follow</a>

              @endif

Something wrong with the if condition?

splendidkeen left a reply on Eloquent-Relationship With Pivot Table/ DB Error • 1 week ago

Updated it, synchronically :D

splendidkeen left a reply on Eloquent-Relationship With Pivot Table/ DB Error • 1 week ago

This works for the DB, but returns: Call to a member function with() on string @tykus

It will store the connection everytime I click the button, so I integrate this

public function alreadyFollows(){
        return $this->stores()->wherePivot('trusted', true)->get();
 }

splendidkeen left a reply on Eloquent-Relationship With Pivot Table/ DB Error • 1 week ago

I am returning the business page, with info that User supported it, after clicking the button. @tykus

splendidkeen left a reply on Eloquent-Relationship With Pivot Table/ DB Error • 1 week ago

Thank you @tykus

It returns:

Call to a member function route() on null

And nothing will be stored.

When I try this:

public function followStore(Business $business){
        $this->stores()->attach($business)->where('id', $business->id)->first()->pivot->update([

            'supported' => true,

        ]);
}

it attaches the correct user and business in the DB, but returns

Call to a member function where() on null

so supported will remain 0

splendidkeen started a new conversation Eloquent-Relationship With Pivot Table/ DB Error • 1 week ago

Hey,

I am trying to let authenticated Users visit a Business, to follow() $business, which will be stored in a pivot table 'supporters' turning the column 'supported' to true.

But I am facing some problems with the supporters table, because it won't get any data. I already tested it for a non-eloquent Model, which worked.

Is there something obvious within the error, that I am not getting?

Pivot table (supporters):

public function up(){
      Schema :: create ('supporters', function(Blueprint $table){
           $table->increments('id');
           $table->integer('user_id');
           $table->integer('business_id');
           $table->boolean('supported');
           $table->timestamps();
       });
}

Business.php

public function users(){
        return $this->belongsToMany(User::class, 'supporters', 'business_id', 'user_id');
}

User.php

public function stores(){
       return $this->belongsToMany(Business::class, 'supporters', 'user_id', 'business_id'); 
}

public function followStore(Business $business){
        $this->attach()->stores()->where('id', $business->id)->first()->pivot->update([
             'supported' => true,
        ]);
}

ProfileController:

public function follow(Business $business, User $user){
        $user = Auth::user();
        $business = Business::where('id', $business->id)->first();

        Auth::user()->followStore($business)
            ->route('partner.show', $business)->with('info', 'Supported.');
}

Route:

Route::get('/stores/add/{business}', [
    'uses' => '[email protected]', 
    'as' => 'stores.add',
    'middleware' => ['auth'],
]);

View:

<a href="{{ route('stores.add', $business) }}">Follow</a>

Results in Error:

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous (SQL: select `business`.*, `supporters`.`user_id` as `pivot_user_id`, `supporters`.`business_id` as `pivot_business_id` from `business` inner join `supporters` on `business`.`id` = `supporters`.`business_id` where `supporters`.`user_id` = 1 and `id` = 1 limit 1)

Thank you

30th November, 2017

splendidkeen left a reply on BadMethodCallException: Method Update Does Not Exist • 1 week ago

Route::get('/products/{product}/edit', [
    'uses' => '[email protected]', 
    'as' => 'products.edit',
    'middleware' => ['auth:partner'],
    ]);

Route::post('/edit/{id}', [
    'uses' => '[email protected]', 
    'middleware' => ['auth:partner'],
    ]);

@Snapey

splendidkeen left a reply on BadMethodCallException: Method Update Does Not Exist • 1 week ago

Understand @Snapey

So if I dd, after validate

dd($request);

it will have a ParameterBag with the array of the new values

Next step is below $product

$product = Product::where('business_id', Auth::id())->findOrFail($id);

dd($product);

results in the same Error, again.

This is the url: /edit/%7Bid%7D

splendidkeen left a reply on BadMethodCallException: Method Update Does Not Exist • 1 week ago

Where could the validation fail? At the beginning it changed the values but for every business related product, that is why I am wondering about the error.

@Snapey

splendidkeen left a reply on BadMethodCallException: Method Update Does Not Exist • 1 week ago

Yes, getNameOrUsername() is used, when I'm logged in as a normal User. But now I am logged in as a Business, with protected routes. That is why I am wondering, because it returns this error from the navigation.blade.php of normal users. @Snapey

splendidkeen left a reply on BadMethodCallException: Method Update Does Not Exist • 1 week ago

No @Snapey, just returns the Call to undefined method Illuminate\Database\Query\Builder Error.

splendidkeen left a reply on BadMethodCallException: Method Update Does Not Exist • 1 week ago

@Snapey

Now its giving me:

Call to undefined method Illuminate\Database\Query\Builder::getNameOrUsername()

the error occurs on a navigation.blade.php, which is not even used on this Auth: system side.

splendidkeen left a reply on BadMethodCallException: Method Update Does Not Exist • 1 week ago

Thank you @Snapey This results in undefined variable: id When I add (Request $request, Product $id) it will get back to Method update() does not exist.

public function postProductEdit(Request $request) {

        
$this->validate($request, [

            'title'=> 'max:25',
            'brand'=> 'max:25',
            'sku'=> 'max:6',
            'description'=> 'max:140',
            'price'=> 'max:10',
            'availability'=> 'max:10',

        ]);

        $product = Product::findOrFail($id);

        $product->update([

            'title' => $request->input('title'),
            'brand' => $request->input('brand'),
            'sku' => $request->input('sku'),
            'description' => $request->input('description'),
            'price' => $request->input('price'),
            'availability' => $request->input('availability'),

        ]);

        return redirect()
            ->route('products.edit', compact('product'));
}
Route::get('/products/{product}/edit', [
    'uses' => '[email protected]getProductEdit', 
    'as' => 'products.edit',
    'middleware' => ['auth'],
    ]);
Route::post('/edit', [
    'uses' => '[email protected]', 
    'middleware' => ['auth'],
    ]);

splendidkeen left a reply on BadMethodCallException: Method Update Does Not Exist • 1 week ago

Thank you @mfoote It is not working at the moment, I will have a look.

splendidkeen left a reply on BadMethodCallException: Method Update Does Not Exist • 1 week ago

@mfoote You are right. The post method route for /edit is not listed.

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.