-1

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="{{ route('hotel.addfalang') }}">
    @method('POST')
    @csrf
    <input type="hidden" name="hotel_id" value="{{ $lastid }}">

    <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 {{ $errors->has('title')? 'is-invalid': ''  }}" placeholder="نام هتل" style="width: 100%">
                @if ($errors->has('title'))
                <div class="invalid-feedback">
                    <strong>{{ $errors->first('title')}}</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>
miken32
  • 42,008
  • 16
  • 111
  • 154
devmrh
  • 1,171
  • 4
  • 19
  • 46
  • What error code are you recieving? Is there something on `/storage/logs/laravel.log`? Blank screens usualy are caused by 500's errors that are stored there. – namelivia Jun 02 '19 at 09:34
  • laravel.log is clean . . – devmrh Jun 02 '19 at 10:14
  • Does this answer your question? [What is the location of Laravel's error logs?](https://stackoverflow.com/questions/37535315/what-is-the-location-of-laravels-error-logs) – miken32 Aug 24 '23 at 22:15

2 Answers2

0

Try:

$validatedData = $request->validate(
    ['title' => 'required']
);

On the documentation the validate method is applied on the request instance, no the controller.

namelivia
  • 2,657
  • 1
  • 21
  • 24
  • i tried this. same result ... if i write any kind of validation i will get blank screen ... but when i remove validation code everything works fine – devmrh Jun 02 '19 at 10:40
0

I had the same problem but I used

Validator::make($request->all(), []) 

which works well.

Marco
  • 2,368
  • 6
  • 22
  • 48
Ali
  • 1
  • 1