dimanche 2 juin 2019

laravel if use validation in controller cause white blank screen

i'm performing validation on some field in request. in my case " title " , when i use any validation in this action it give me white blank screen with no information, i tried using seprate Request validation file... if i remove validation everything will be ok! why this happening?

(php error log and laravel debugging are already on).

this is the dd() result in target controller action:

array:9 [▼
  "_method" => "POST"
  "_token" => "XW8ifwaPFlnA31mqlF3rjLz0iDyAxSpayr6G11WJ"
  "hotel_id" => "63"
  "lang" => "fa"
  "title" => null
  "meta" => null
  "keywords" => null
  "address" => null
  "cancelterms" => null
]

this is my form action:

public function addFaLang(Request $request)
{

      dd($request->all());


     $this->validate(
       $request,
         ['title' => 'required'],
         ['title.required' => 'please fill this']
     );



    $hotel_id = $request->get('hotel_id');


    $hotel_translates = HotelTranslate::where(['hotel_id' =>  $hotel_id, 'lang' => 'fa'])->count();

    if ($hotel_translates) {
        HotelTranslate::where(['hotel_id' =>  $hotel_id, 'lang' => 'fa'])->delete();
    }

    if ($request->title) {
        $hotel_tra = HotelTranslate::create($request->only( 'hotel_id', 'title', 'meta', 'keywords', 'address', 'cancel_term', 'lang'));
        $hotel_tra->save();
    }


    $result = array('result' => 1, 'idhotel' => $hotel_id, 'message' => 'success');

    return view('adminarea.hotel.create-hotel-ar-lang', $result);
}

this is my form:

form method="post" action="">
    @method('POST')
    @csrf
    <input type="hidden" name="hotel_id" value="">

    <table class="table table-bordered table-striped">
        <div class="progress">
            <div class="progress-bar progress-bar-striped" role="progressbar" aria-valuenow="40" aria-valuemin="0"
                aria-valuemax="100" style="width: 40%"></div>
        </div>
        <tr>
            <td>
                <label>زبان فارسی
                    <input type="hidden" name="lang" value="fa">

                </label>

            </td>
        </tr>
        <tr>
            <td>
                <input type="text" name="title" class="form-control " placeholder="نام هتل" style="width: 100%">
                @if ($errors->has('title'))
                <div class="invalid-feedback">
                    <strong></strong>
                </div>
                @endif
            </td>
        </tr>
        <tr>
            <td>
                <input type="text" name="meta" class="form-control" placeholder="متا" style="width: 100%">
            </td>
        </tr>
        <tr>
            <td>
                <input type="text" name="keywords" class="form-control" placeholder="کلید واژه"
                    style="width: 100%">
            </td>
        </tr>
        <tr>
            <td>
                <input type="text" name="address" class="form-control" placeholder="آدرس" style="width: 100%">
            </td>
        </tr>
        <tr>
            <td>
                <input type="text" name="cancelterms" class="form-control" placeholder="قوانین کنسلی"
                    style="width: 100%">
            </td>
        </tr>

        <tr>
            <td>
                <input type='submit' value='مرحله بعد' class='btn btn-success' style="float:left">
            </td>
        </tr>
    </table>
</form>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire