Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 1426
Alex Hales
  • 0
Alex HalesTeacher
Asked: May 30, 20222022-05-30T15:19:34+00:00 2022-05-30T15:19:34+00:00

php – SQLSTATE[HY000]: General error: 1366 Incorrect integer value

  • 0

[ad_1]

I’m a bit new to a project Laravel and i’m currently block on an error since hours.

I’m trying to make a select multiple, it’s working when the select is unique but when i try to have the possibility to select multiple option, it doesn’t work.

Here the view :

            <label for="operation_id" class="text-gray-700 inline-block">Opération</label>
        <select class="focus:outline-none outline-none w-full px-3 py-2 border rounded {{ $errors->has('operation_id') ? 'border-red-400' : '' }} select-checkbox" name="operation_id[]" id="operation_id" multiple>
            @foreach ($operations as $operation)
                @if (old('operation_id', $offer->operation_id ?? '') == $operation->id)
                    <option value="{{ $operation->id }}" selected {{ in_array($operation->id,  old('operation_id') ?: []) }}>{{ $operation->translation->name }}</option>
                @else
                    <option value="{{ $operation->id }}">{{ $operation->translation->name }}</option>
                @endif
            @endforeach
        </select>

        @if ($errors->has('operation_id'))
            <div class="invalid-feedback">
                <strong>{{ $errors->first('operation_id') }}</strong>
            </div>
        @endif

Then the controller :

class OfferController extends Controller
{

use UploadTrait;


/**
 * Display a listing of the resource.
 *
 * @return \Illuminate\Http\Response
 */
public function index(Request $request)
{
  return view('dashboard.offers.index');
}

/**
 * Show the form for creating a new resource.
 *
 * @return \Illuminate\Http\Response
 */
public function create()
{
    $doctors = Doctor::get();
    $operations = Operation::with([
        'translation' => function($q) {
            return $q->where('language_code', app()->getLocale());
        }
    ])
    ->get();

    $hotels = Hotel::get();
    $currencies = Currency::get();

    return view('dashboard.offers.create', compact( 'doctors', 'operations', 'hotels', 'currencies'));
}

/**
 * Show the form for editing the specified resource.
 *
 * @param  Offer  $offer
 * @return \Illuminate\Http\Response
 */
public function edit(Offer $offer)
{
    $language = \App\Models\Language::where('language', request()->input('lang', env('APP_LANG', 'fr_FR')))->firstOrFail();

    $offer->load(['translations']);


    $doctors = Doctor::get();
    $operations = Operation::with([
        'translation' => function ($q) {
            return $q->where('language_code', app()->getLocale());
        }
    ])
    ->get();


    $hotels = Hotel::get();
    $currencies = Currency::get();

    return view('dashboard.offers.edit', compact('offer', 'doctors', 'operations', 'hotels', 'currencies', 'language'));

}

/**
 * Store a newly created resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function store(OfferRequest $request)
{
  $offer = Offer::create($request->only('price', 'hotel_included', 'recommended_stay', 'hospitalisation', 'visible', 'operation_id', 'doctor_id', 'hotel_id', 'hospitalisation', 'price_fixed', 'currency', 'promote', 'first_picture'));

  $offer->translations()->create([
      'language_code' => env('APP_LOCAL', app()->getLocale()),
      'title' => $request->title,
      'features' => $request->features,
  ]);

  $operationId = collect($request->input('operation_id'))->keys();
    $offer->operations()->attach($operationId);

  return redirect()->route('admin.offers.index')->with('success', 'Une nouvelle offre a été enregistrée');
}


/**
 * Update the specified resource in storage.
 *
 * @param  \Illuminate\Http\OfferRequest  $request
 * @param  OfferTranslation  $offerTranslation
 * @return \Illuminate\Http\RedirectResponse
 */
public function update(OfferRequest $request, Offer $offer)
{


    $offer->update($request->only('price', 'hotel_included', 'recommended_stay', 'hospitalisation', 'visible', 'operation_id', 'doctor_id', 'hotel_id', 'hospitalisation', 'price_fixed', 'currency', 'promote', 'first_picture'));

    $language = \App\Models\Language::where('language', request()->input('lang', env('APP_LANG', 'fr_FR')))->firstOrFail();


    $offer->translations()->updateOrCreate(
        ['offer_id' => $offer->id, 'language_code' => $language->language],
        $request->only('title', 'features')
    );

    $operationId = collect($request->input('operation_id'))->keys();
    $offer->operations()->sync($operationId);

    return redirect()->route('admin.offers.index')->with('success', "L'offre a été mise à jour");
}

When i try to update, i get this error :
SQLSTATE[HY000]: General error: 1366 Incorrect integer value: ‘[“1”]’ for column ‘operation_id’ at row 1 (SQL: update offers set operation_id = [“1”], offers.updated_at = 2022-05-30 14:56:42 where id = 1)

Message error

I don’t know from where come the error. Thank in advance of ur help

[ad_2]

  • 0 0 Answers
  • 17 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 4775 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 1063 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 1009 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.