-2

I want create update data from table users with field kupon, so project enduser have kupon 100 and then enduser can input to field car, motor for input kupon from he have 100 kupon. Logic car<=kupon.

Controller

public function __construct()
{
    $this->middleware('auth');
}

/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Http\Response
 */
public function index()
{
    return view('lucky');
}

public function update()
{
    $users = Users::get();
    foreach ($users as $user) {
        $user->umroh = umroh;
        $user->save();
    }
}

Views

<form action="/lucky.update" method="post">
    {{ csrf_field() }}
    <input type="hidden" name="_method" value="PUT">
    <label for="umroh"> umroh</label>
    <input type="number" value="{{$user->umroh}}"><br>
    <input type="submit" name="submit" value="edit">

 </form>

Route

Auth::routes();
Route::resource('lucky', 'LuckyController');

somebody help me. I have time only 42 hour begin this post.

Md.Sukel Ali
  • 2,987
  • 5
  • 22
  • 34
reyza
  • 1
  • 1
  • 2
    You should probably stat by being more clear about what you have and what you want to achieve. I barely understand the issue you have from what you wrote. – Indra Feb 06 '19 at 10:07

1 Answers1

0

i have no idea what you are trying to accomplish but here is a cleaner version of the code.

  • fixed the form to actualy send umroh to the backend.
  • added the request and id paramenter to the controller
  • used the request->umroh to actually save the new umroh to the user

Controller

public function __construct()
{
    $this->middleware('auth');
}

/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Http\Response
 */
public function index()
{
    return view('lucky');
}

public function update(Request $request, $id)
{
    $user = Users::find($id);
    $user->umroh = request->umroh;
    $user->save();

    return redirect()->back();
}

Views

<form action="{{route('lucky.update', ['id' => $user->id])}}" method="post">
    {{ csrf_field() }}
    <input type="hidden" name="_method" value="PUT">
    <label for="umroh"> umroh</label>
    <input type="number" name="umroh" value="{{$user->umroh}}"><br>
    <input type="submit" name="submit" value="edit">

 </form>

Route

Auth::routes();
Route::resource('lucky', 'LuckyController');
Community
  • 1
  • 1
mrQubeMaster
  • 342
  • 2
  • 14
  • Thanks mrQubeMaster, i can try but i could new problem "MethodNotAllowedHttpException in RouteCollection.php line 218:" you are understand ? – reyza Feb 07 '19 at 02:06
  • is the error on loading the page or on submit of the form? if the error is on loading the page you have a problem in your route file but its probably on form submit. https://stackoverflow.com/questions/19760585/laravel-throwing-methodnotallowedhttpexception you could use `@method('PUT')` instead of `` – mrQubeMaster Feb 07 '19 at 08:27