tallaljamshed

tallaljamshed

Member Since 4 Months Ago

Experience Points
550
Total
Experience

4,450 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
0
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 1
550 XP
May
22
1 week ago
Activity icon

Replied to Using Mysql Load Data Query As A Raw Laravel Query

alright thanks i understand now :)

Activity icon

Replied to Using Mysql Load Data Query As A Raw Laravel Query

@bryank thanks that worked perfectly. although i used fewer lines which i will show here for anyone else like me .

$file = base_path('public/csv/'.$request->csv);
$pdo = DB::connection()->getPdo();
$sql = "LOAD DATA LOCAL INFILE '$file' INTO TABLE $request->table FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\n' IGNORE 1 ROWS";
$pdo->exec($sql);
return redirect()->back();

and in config/database.php

'mysql' => [
            'driver' => 'mysql',
            ...
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
                PDO::MYSQL_ATTR_LOCAL_INFILE => true,
            ]) : [],

is there any problem with this way ? other then using $request->table directly in query .

this link was helpful https://laracasts.com/discuss/channels/laravel/load-data-infile

Activity icon

Replied to Using Mysql Load Data Query As A Raw Laravel Query

thanks @bryank i just did that before looking at your answer. i thinks there is some progress but now im getting this error .

SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.

:(

Activity icon

Started a new Conversation Using Mysql Load Data Query As A Raw Laravel Query

Hi im trying to use this query

LOAD DATA INFILE 'c:/tmp/discounts.csv' 
INTO TABLE discounts 
FIELDS TERMINATED BY ',' 
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;

in laravel as raw query but that line terminating character actually takes the query on new line and it does not work .

$upload = DB::raw("LOAD DATA INFILE '$file' INTO TABLE '$request->table' FIELDS TERMINATED by ',' LINES TERMINATED BY '\n' IGNORE 1 ROWS");

this is the error

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''teachertest' FIELDS TERMINATED by ',' LINES TERMINATED BY ' ' IGNORE 1 ROWS' at line 1 
Apr
22
1 month ago
Activity icon

Replied to How To Prevent .ZIP File Upload

ok i'll try to explain further PLEASE READ IT ALL. @oussama.tn @michaloravec I made this web app to upload files with all proper validation for office files. As far as i knew all validations worked . No file other then docs, pdf, ppt, excel were uploading. but some how (could be hacking attempt) somebody uploaded what LOOKS LIKE a zip file. why i say LOOKS LIKE a zip file? beacause im saving file name and mime types in database. now these (SUSPICIOUS) Files does not have any extension with its file name (which all other valid files do). and the mime type is

application/octet-stream

ok now i downloaded this file and it downloads as .ZIP file and opens with winrar. and theres some XML files in it. further i tried to investigate, and uploaded some other zip file from my pc which was blocked by validation(which is a good thing), but tried to re-upload that (SUSPICIOUS) file and it does upload again . So neither mimes nor mimetype validation is stoping it . PS: when i re-uploaded that (SUSPICIOUS) file this time it shows extension .zip and mimetype as

application/x-zip-compressed

ive been stuck with these types of file errors and havnt got much help so far on this forum so KINDLY SOME ONE HELP

Activity icon

Started a new Conversation How To Prevent .ZIP File Upload

I'm using general file validations in laravel for word, excel, ppt (etc) but it allows zip files to be uploaded. how can i stop that,

Apr
21
1 month ago
Activity icon

Replied to File Upload Validation Dones't Work With ZIP

ok i have a problem . i used validation for mime types of all word files and pdf they are working fine. BUT i want it to stop accepting zip file and others that dont have any extention or those that are application/octet-stream. How can i do that.???

Apr
20
1 month ago
Activity icon

Replied to File MIME Type Validation Error, Ppt Vs Pptx

:( anyone else u know @snapey please tag them

Activity icon

Replied to File MIME Type Validation Error, Ppt Vs Pptx

@snapey can u take a look at this. also on some other forum I read this. "A security fix implemented in WordPress 4.7.1 relies on a PHP extension (fileinfo) with inconsistent reporting behavior. As a result, many users trying to upload various types of files (office documents, multimedia, fonts, etc.) have received validation errors." and others are also talking about (fileinfo) not being accurate. Is this the same problem with Laravel????

Activity icon

Replied to File MIME Type Validation Error, Ppt Vs Pptx

someone mentioned it could be Linux server doing it (AS i am on shared hosting). but i checked the mimetypes tab of cpanel and my required mime type is listed there which is ( application/vnd.ms-powerpoint )

Activity icon

Replied to File MIME Type Validation Error, Ppt Vs Pptx

I just did

dd($request->file('file_name')->getMimeType());

and it says

"application/CDFV2"

now what kind of powerpoint file is that :(

Activity icon

Started a new Conversation File MIME Type Validation Error, Ppt Vs Pptx

ok so this is my validation.

'file_name' => ['required','file','max:10240', 'mimetypes : application/pdf , application/vnd.ms-excel , application/msword , application/vnd.openxmlformats-officedocument.wordprocessingml.document , application/vnd.openxmlformats-officedocument.spreadsheetml.sheet , application/vnd.ms-powerpoint , application/vnd.openxmlformats-officedocument.presentationml.presentation'],

that includes all office file type (all those that i need). now PPTX file types gets checked correctly and uploaded with mime type

application/vnd.openxmlformats-officedocument.presentationml.presentation

BUT now i have PPT file which it says is invalid. with this mime type

application/vnd.ms-powerpoint

what could be possibly wrong????????

PS: theres no spaces in mime types i just put them here

Activity icon

Replied to 10mb File Validation Problem

So u mean in base64 .Atleast data wont get truncated ? then i can just increase post_max_size?.

Apr
15
1 month ago
Activity icon

Replied to 10mb File Validation Problem

But you see the error is from laravel . So the file is actually passing through with correct name "std_file". but laravel is not sending back custom message , that is what confusing me , and the PHP (max post size error) comes on 12mb file not on 10mb. also the max_post_size on php config is 40M. SO ITS ALL VERY CONFUSING

Activity icon

Started a new Conversation 10mb File Validation Problem

This is a strange problem for me. i'm validating file with max:5000 . Then i'm uploading a file of size 9,980kb it gives the error "Allowed file size is 5000" which is perfectly fine. but when im uploading a file of size 10,367kb (more then 10mb), it does give me error but like this "The std file failed to upload". I mean i have a custome message right there, but its not showing that on 10mb file,

$validator = Validator::make($request->all(),[
            'std_file'=>['required','file','max:5000'],
        ],[
            'std_file.required' => "Please Select a File to Upload",
            'std_file.file' => "Invalid file type",
            'std_file.max' => "Allowed file size is :max",
        ]);
Mar
19
2 months ago
Activity icon

Replied to Laravel MS Office Files Upload Validation

no that was just the [ input="file_name" ] from submited form . changed it already

Activity icon

Replied to Laravel MS Office Files Upload Validation

OK Problem solved with interesting findings.

  1. Removing Spaces between commas. was not always an issue , in some files it helps but in others it dosn't .... so in general no spaces is a good idea.

  2. Empty files are not validated dont know if it was an obvious thing but ,, first time for me lol ,, . ONLY empty PDF works.

Activity icon

Replied to Laravel MS Office Files Upload Validation

BTW ....PDF uploading works

Activity icon

Replied to Laravel MS Office Files Upload Validation

Nope Just removed spaces not working

Activity icon

Started a new Conversation Laravel MS Office Files Upload Validation

So im trying to upload MS Office files like word, excel, power point AND ...PDF file, but its not working with both mimes and mimetypes, .. can someone help <// THE FIELD UNDER VALIDATION IS file_name//>

$validator =  Validator::make($data, [
            'degree_id' => ['required', 'integer' ,'exists:degrees,degree_id'],
            'course_id' => ['required', 'integer' ,'exists:courses,course_id'],

//            'file_name' => ['required','max:5120'],
            'file_type' => ['required',Rule::in(['course', 'assignment'])],
            'file_name' => ['required', 'mimetypes:application/pdf,application/vnd.ms-excel,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation'],
        ],[
            'degree_id.required' => 'Degree is Required',
            'degree_id.integer' => 'Degree id should be an integer',
            'degree_id.exists' => 'Degree is invalid',

            'course_id.required' => 'Course is Required',
            'course_id.integer' => 'Course id should be an integer',
            'course_id.exists' => 'Course is invalid',

            'file_name.required' => 'File is Required',
            'file_name.max' => 'Allowed file size is 5MB',
            'file_name.mimetypes' => 'Mime type is invalid',

             'file_type.required' => 'File type is Required',
             'file_type.in' => 'This file type is not allowed',
        ]);
Jan
10
4 months ago
Activity icon

Replied to Laravel Custom Form Request Only Process 11 Or 12 Validation Rules

Thanks man that worked had no idea of that . So by default it was cookies. Does this mean cookies don't store enough data ? That's why I was getting all errors.

Activity icon

Replied to Laravel Custom Form Request Only Process 11 Or 12 Validation Rules

alright thanks this is my first question u taught me alot :) ... where are these people @nakov @snapey can u ask them to take a look

Activity icon

Replied to Laravel Custom Form Request Only Process 11 Or 12 Validation Rules

ohoooo .... I KNOW they are null ...... and i WANT it to SHOW ME ERRORS when they are null .... it is showing me errors for only 12 rules ..... as soon as i add 13th rule ..... it stops showing me ERRORS ...... I also tried (automatic redirection) AND (manual redirection) after validation ....... nothing changes :( @jove

also how did u add grey box , my code is adding

 black box
Activity icon

Replied to Laravel Custom Form Request Only Process 11 Or 12 Validation Rules

@jove here is the request

Illuminate\Http\Request {#51 ▼
  #json: null
  #convertedFiles: null
  #userResolver: Closure($guard = null) {#31 ▶}
  #routeResolver: Closure() {#252 ▶}
  +attributes: Symfony\Component\HttpFoundation\ParameterBag {#53 ▶}
  +request: Symfony\Component\HttpFoundation\ParameterBag {#52 ▼
    #parameters: array:22 [▼
      "_token" => "oP2QuJKFc5QkWd0WgbhfEHREIpJ4PunSqUqQElHA"
      "submit" => "submit"
      "fk_school_id" => null
      "sc_br_name" => null
      "sc_br_address" => null
      "sc_br_status" => "1"
      "no_of_boys" => null
      "no_of_girls" => null
      "sc_br_covered_area" => null
      "no_of_teachers" => null
      "owner_name" => null
      "owner_phone" => null
      "owner_email" => null
      "principal_name" => null
      "principal_phone" => null
      "principal_email" => null
      "pov_for_subarea" => null
      "city_for_subarea" => null
      "areaselect" => null
      "latitude" => null
      "longitude" => null
      "location_string" => null
    ]
  }
  +query: Symfony\Component\HttpFoundation\ParameterBag {#59 ▶}
  +server: Symfony\Component\HttpFoundation\ServerBag {#55 ▶}
  +files: Symfony\Component\HttpFoundation\FileBag {#56 ▶}
  +cookies: Symfony\Component\HttpFoundation\ParameterBag {#54 ▶}
  +headers: Symfony\Component\HttpFoundation\HeaderBag {#57 ▶}
  #content: null
  #languages: null
  #charsets: null
  #encodings: null
  #acceptableContentTypes: null
  #pathInfo: "/school/addbranch"
  #requestUri: "/school/addbranch"
  #baseUrl: ""
  #basePath: null
  #method: "POST"
  #format: null
  #session: Illuminate\Session\Store {#284 ▶}
  #locale: null
  #defaultLocale: "en"
  -preferredFormat: null
  -isHostValid: true
  -isForwardedValid: true
  basePath: ""
  format: "html"
}

and btw even if i introduce latitude which is just an input and not select . it shows same behavior.

ALSO TELL ME if there is any way i can show all the data coming into my view... it looks like with 13 rules . it is still validating and returning to previous page but not returning any messages within $error. i also tried both ways (giving custom messages) and (without custome messages)

Activity icon

Replied to Laravel Custom Form Request Only Process 11 Or 12 Validation Rules

@jove can u just look at this full project on git cause this is fucked up. I just made a new laravel project and added code pieces from old project and made the whole request validation again but still getting the exact same issue.

https://github.com/TallalJamshed/registrations

Activity icon

Replied to Laravel Custom Form Request Only Process 11 Or 12 Validation Rules

but the possibility of wrong input names is not there because as i already told u . i used random 12 rules out of 18 . and 12 works at a time . but as soon as i add 13th rule ( ANY 13th RULE ) it just stops returning errors.....

Activity icon

Replied to Laravel Custom Form Request Only Process 11 Or 12 Validation Rules

@jove ok sorry for not posting full code it gets too long , but now i edited the previous reply with full code take a look

Activity icon

Replied to Laravel Custom Form Request Only Process 11 Or 12 Validation Rules

I also tried putting these validation within controller

$validator = validator::make($request->all() , $rules , $messages)->validate(); 

... it all works with other controller and forms but they dont have as many validation rules

Activity icon

Replied to Laravel Custom Form Request Only Process 11 Or 12 Validation Rules

// Full Form //

<form  method="POST" action="{{route('addschoolbranchindb')}}">
        @csrf
        <div class="col-xl-12 order-xl-1 mt-5">
            <div class="card bg-secondary shadow">
                <div class="card-header bg-white border-0">
                    <div class="row align-items-center">
                        <div class="col-8">
                            <h3 class="mb-0">Add School Branch</h3>
                        </div>
                        <div class="col-4 text-right">
                            <input type="submit" value="submit" name="submit" class="btn btn-sm btn-primary">
                        </div>
                    </div>
                </div>
                <div class="card-body">
                   {{ count($errors) }}
                    {{ dd($errors) }}
                    <h6 class="heading-small text-muted mb-4">School information</h6>
                    <div class="row mt-4">
                        <div class="col-md-6">
                            <div class="col-md-4">
                                <label style="font-weight:bold; width:100%" class="" for="fk_school_id">Select School</label>
                            </div>
                            <div class="col-md-8">
                                <select class="form-control form-control-alternative fk_school_id" id="fk_school_id" name="fk_school_id">
                                    <option value=""></option>
                                    @foreach ($schools as $school)
                                        <option value="{{$school->school_id}}">{{$school->school_name}}</option>
                                    @endforeach
                                </select>
                            </div>
                            <div class="row" style="text-align:center">
                                <div class="col-md-8">
                                    @error('fk_school_id')
                                        <span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
                                    @enderror
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="col-md-4">
                                <label style="font-weight:bold" class="" for="sc_br_name">Branch Name</label>
                            </div>
                            <div class="col-md-8">
                                <input type="text" id="sc_br_name" name="sc_br_name" class="disable_on_sc_id form-control form-control-alternative" 
                                placeholder="Branch Name">
                            </div>
                            <div class="row" style="text-align:center">
                                <div class="col-md-8">
                                    @error('sc_br_name')
                                        <span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
                                    @enderror
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row mt-4">
                        <div class="col-md-6">
                            <div class="col-md-4">
                                <label style="font-weight:bold" class="" for="sc_br_address">School Address</label>
                            </div>
                            <div class="col-md-8">
                                <input type="text" id="sc_br_address" name="sc_br_address" class="disable_on_sc_id form-control form-control-alternative" 
                                placeholder="School Address">
                            </div>
                            <div class="row" style="text-align:center">
                                <div class="col-md-8">
                                    @error('sc_br_address')
                                        <span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
                                    @enderror
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="col-md-4">
                                <label style="font-weight:bold" class="" for="sc_br_status">School status</label>
                            </div>
                            <div class="col-md-8">
                                <select class="disable_on_sc_id form-control form-control-alternative sc_br_status" id="sc_br_status" name="sc_br_status">
                                    <option value="1">Un-Registered</option>
                                    <option value="2">Under Process</option>
                                    <option value="3">Registered</option>
                                    {{-- @foreach ($schools as $school)
                                        <option value="{{$school->school_id}}">{{$school->school_name}}</option>
                                    @endforeach --}}
                                </select>
                            </div>
                            <div class="row" style="text-align:center">
                                <div class="col-md-8">
                                    @error('sc_br_status')
                                        <span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
                                    @enderror
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row mt-4">
                        <div class="col-md-6">
                            <div class="col-md-4">
                                <label style="font-weight:bold" class="" for="no_of_boys">No of Boys</label>
                            </div>
                            <div class="col-md-8">
                                <input type="text" id="no_of_boys" name="no_of_boys" class="disable_on_sc_id form-control form-control-alternative" 
                                placeholder="Number of Boys">
                            </div>
                            <div class="row" style="text-align:center">
                                <div class="col-md-8">
                                    @error('no_of_boys')
                                        <span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
                                    @enderror
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="col-md-4">
                                <label style="font-weight:bold" class="" for="no_of_girls">No of Girls</label>
                            </div>
                            <div class="col-md-8">
                                <input type="text" id="no_of_girls" name="no_of_girls" class="disable_on_sc_id form-control form-control-alternative" 
                                placeholder="Number of girls">
                            </div>
                            <div class="row" style="text-align:center">
                                <div class="col-md-8">
                                    @error('no_of_girls')
                                        <span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
                                    @enderror
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row mt-4">
                        <div class="col-md-6">
                            <div class="col-md-4">
                                <label style="font-weight:bold" class="" for="sc_br_covered_area">Covered Area</label>
                            </div>
                            <div class="col-md-8">
                                <input type="text" id="sc_br_covered_area" name="sc_br_covered_area" class="disable_on_sc_id form-control form-control-alternative" 
                                placeholder="Total Covered Area">
                            </div>
                            <div class="row" style="text-align:center">
                                <div class="col-md-8">
                                    @error('sc_br_covered_area')
                                        <span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
                                    @enderror
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="col-md-4">
                                <label style="font-weight:bold" class="" for="no_of_teachers">No of Teachers</label>
                            </div>
                            <div class="col-md-8">
                                <input type="text" id="no_of_teachers" name="no_of_teachers" class="disable_on_sc_id form-control form-control-alternative" 
                                placeholder="Number Of Teachers">
                            </div>
                            <div class="row" style="text-align:center">
                                <div class="col-md-8">
                                    @error('no_of_teachers')
                                        <span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
                                    @enderror
                                </div>
                            </div>
                        </div>
                    </div>

                    <hr class="my-4" />

                    <h6 class="heading-small text-muted mb-4">Owner information</h6>

                    <div class="row">
                        <div class="col-md-6">
                            <div class="col-md-4">
                                <label style="font-weight:bold" class="" for="owner_name">Owner Name</label>
                            </div>
                            <div class="col-md-8">
                                <input type="text" id="owner_name" name="owner_name" class="disable_on_sc_id form-control form-control-alternative" 
                                placeholder="Owner Name">
                            </div>
                            <div class="row" style="text-align:center">
                                <div class="col-md-8">
                                    @error('owner_name')
                                        <span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
                                    @enderror
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="col-md-5">
                                <label style="font-weight:bold" class="" for="owner_phone">Owner Phone No</label>
                            </div>
                            <div class="col-md-7">
                                <input type="text" id="owner_phone" name="owner_phone" class="disable_on_sc_id form-control form-control-alternative" 
                                placeholder="Owner Number">
                            </div>
                            <div class="row" style="text-align:center">
                                <div class="col-md-8">
                                    @error('owner_phone')
                                        <span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
                                    @enderror
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row mt-5">
                        <div class="col-md-6">
                            <div class="col-md-4">
                                <label style="font-weight:bold" class="" for="owner_email">Owner Email</label>
                            </div>
                            <div class="col-md-8">
                                <input type="text" id="owner_email" name="owner_email" class="disable_on_sc_id form-control form-control-alternative" 
                                placeholder="Owner Email">
                            </div>
                            <div class="row" style="text-align:center">
                                <div class="col-md-8">
                                    @error('owner_email')
                                        <span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
                                    @enderror
                                </div>
                            </div>
                        </div>
                    </div>

                    <hr class="my-4" />

                    <h6 class="heading-small text-muted mb-4">Principal information</h6>

                    <div class="row">
                        <div class="col-md-6">
                            <div class="col-md-4">
                                <label style="font-weight:bold" class="" for="principal_name">Principal Name</label>
                            </div>
                            <div class="col-md-8">
                                <input type="text" id="principal_name" name="principal_name" class="disable_on_sc_id form-control form-control-alternative" 
                                placeholder="Principal Name">
                            </div>
                            <div class="row" style="text-align:center">
                                <div class="col-md-8">
                                    @error('principal_name')
                                        <span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
                                    @enderror
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="col-md-5">
                                <label style="font-weight:bold" class="" for="principal_phone">Principal Phone No</label>
                            </div>
                            <div class="col-md-7">
                                <input type="text" id="principal_phone" name="principal_phone" class="disable_on_sc_id form-control form-control-alternative" 
                                placeholder="Principal Number">
                            </div>
                            <div class="row" style="text-align:center">
                                <div class="col-md-8">
                                    @error('principal_phone')
                                        <span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
                                    @enderror
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row mt-5">
                        <div class="col-md-6">
                            <div class="col-md-4">
                                <label style="font-weight:bold" class="" for="principal_email">Principal Email</label>
                            </div>
                            <div class="col-md-8">
                                <input type="text" id="principal_email" name="principal_email" class="disable_on_sc_id form-control form-control-alternative" 
                                placeholder="Principal Email">
                            </div>
                            <div class="row" style="text-align:center">
                                <div class="col-md-8">
                                    @error('principal_email')
                                        <span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
                                    @enderror
                                </div>
                            </div>
                        </div>
                    </div>

                    <hr class="my-4" />
                        
                    <h6 class="heading-small text-muted mb-4">Area information</h6>

                    <div class="row">
                        <div class="col-md-6">
                            <div class="col-md-4">
                                <label style="font-weight:bold" class="" for="pov_for_subarea">Select Province</label>
                            </div>
                            <div class="col-md-8">
                                <select class="form-control form-control-alternative pov_for_subarea" id="pov_for_subarea" name="pov_for_subarea">
                                    <option value=""></option>
                                    @foreach ($provinces as $province)
                                        <option value="{{$province->province_id}}">{{$province->province_name}}</option>
                                    @endforeach
                                </select>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="col-md-5">
                                <label style="font-weight:bold" class="" for="city_for_subarea">Select City</label>
                            </div>
                            <div class="col-md-7">
                                <select class="form-control form-control-alternative city_for_subarea" id="city_for_subarea" name="city_for_subarea">
                                    <option value=""></option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="row mt-5">
                        <div class="col-md-6">
                            <div class="col-md-5">
                                <label style="font-weight:bold" class="" for="areaselect">Select Area</label>
                            </div>
                            <div class="col-md-7">
                                <select class="form-control form-control-alternative areaselect" id="areaselect" name="areaselect">
                                    <option value=""></option>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="col-md-5">
                                <label style="font-weight:bold" class="" for="fk_subarea_id">Select Sub-Area</label>
                            </div>
                            <div class="col-md-7">
                                <select class="form-control form-control-alternative fk_subarea_id" id="fk_subarea_id" name="fk_subarea_id">
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="row mt-5">
                        <div class="col-md-6">
                            <div class="col-md-5">
                                <label style="font-weight:bold" class="" for="latitude">Latitude</label>
                            </div>
                            <div class="col-md-7">
                                <input  type="text" id="latitude" name="latitude" class="form-control form-control-alternative" 
                                placeholder="Latitude">
                            </div>
                            <div class="row" style="text-align:center">
                                <div class="col-md-8">
                                    @error('latitude')
                                        <span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
                                    @enderror
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="col-md-5">
                                <label style="font-weight:bold" class="" for="longitude">Longitude</label>
                            </div>
                            <div class="col-md-7">
                                <input  type="text" id="longitude" name="longitude" class="form-control form-control-alternative" 
                                placeholder="Longitude">
                            </div>
                            <div class="row" style="text-align:center">
                                <div class="col-md-8">
                                    @error('longitude')
                                        <span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
                                    @enderror
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row mt-5">
                        <div class="col-md-6">
                            <div class="col-md-5">
                                <label style="font-weight:bold" class="" for="location_string">Location String</label>
                            </div>
                            <div class="col-md-7">
                                <input  type="text" id="location_string" name="location_string" class="form-control form-control-alternative" 
                                placeholder="Location String">
                            </div>
                            <div class="row" style="text-align:center">
                                <div class="col-md-8">
                                    @error('location_string')
                                        <span class="ml-auto mr-auto" style="color:red">{{$message}}</span>
                                    @enderror
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>

// the route //

Route::post('/school/addbranch','[email protected]')->name('addschoolbranchindb');

// the controller //

public function addSchoolBranchInDb(SchoolBranchRequest $request)
    {
        $sc_branch = new Schoolbranch;
        $sc_branch->fill($request->all());     
        $sc_branch->save();                                                                                                       
        Session::flash('message','School Branch is added');
        Session::flash('alert-class', 'alert-success'); 
        return redirect()->back();
    }

// the validatorn in App\Http\Requests\SchoolBranchRequest //

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class SchoolBranchRequest extends FormRequest
{

    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        $rules = [
            'fk_school_id' => 'required',
            'sc_br_name' => 'required',
            'sc_br_address' => 'required',
            'sc_br_status' => 'required',
            'no_of_boys' => 'required',
            'no_of_girls' => 'required',
            'sc_br_covered_area' => 'required',
            'no_of_teachers' => 'required',
            'owner_name' => 'required',
            'owner_phone' => 'required',
            'owner_email' => 'required',
            'principal_name' => 'required',
            'principal_phone' => 'required',
            'principal_email' => 'required',
            // 'fk_subarea_id' => 'required',
            // 'latitude' => 'required',
            // 'longitude' => 'required',
            // 'location_string' => 'required',


        ];
        return $rules;
    }

    public function messages()
    {
        $messages = [
            'fk_school_id.required' => 'School Name is required',
            'sc_br_name.required' => 'School Branch Name is required',
            'sc_br_address.required' => 'School Address is required',
            'sc_br_status.required' => 'School Status is required',
            'no_of_boys.required' => 'Number of boys is required',
            'no_of_girls.required' => 'Number of girls is required',
            'sc_br_covered_area.required' => 'School covered area is required',
            'no_of_teachers.required' => 'Number of teachers is required',
            'owner_name.required' => 'Owner Name is required',
            'owner_phone.required' => 'Owner Phone is required',
            'owner_email.required' => 'Owner Email is required',
            'principal_name.required' => 'Principal Name is required',
            'principal_phone.required' => 'Principal Phone is required',
            'principal_email.required' => 'Principal Email is required',
            // 'fk_subarea_id.required' => 'Subarea is required',
            // 'latitude.required' => 'Latitude is required',
            // 'longitude.required' => 'Longitude is required',
            // 'location_string.required' => 'Location String is required',


        ];
        return $messages;
    }
}

// the 12 errors //

Illuminate\Support\ViewErrorBag {#299 ▼
  #bags: array:1 [▼
    "default" => Illuminate\Support\MessageBag {#300 ▼
      #messages: array:11 [▼
        "fk_school_id" => array:1 [▼
          0 => "School Name is required"
        ]
        "sc_br_name" => array:1 [▶]
        "sc_br_address" => array:1 [▶]
        "no_of_boys" => array:1 [▶]
        "no_of_girls" => array:1 [▶]
        "sc_br_covered_area" => array:1 [▶]
        "no_of_teachers" => array:1 [▶]
        "owner_name" => array:1 [▶]
        "owner_phone" => array:1 [▶]
        "owner_email" => array:1 [▶]
        "principal_name" => array:1 [▶]
      ]
      #format: ":message"
    }
  ]
}

///// but the 13th rules active and no error /////

Illuminate\Support\ViewErrorBag {#301 ▼
  #bags: []
}

//// im using dd($errors) to show this error bag stuff ///

{{ dd($errors) }}
Jan
07
4 months ago
Activity icon

Started a new Conversation Laravel Custom Form Request Only Process 11 Or 12 Validation Rules

I have 18 validation rules and only 12 runs at a time. So when I submit a form it has 18 inputs. I made 18 rules in a custom validation (App\Http\Requests\CustomValidationRequest) . only (random) 12 rules work and returns errors. If I add 13th rule it does returns to previous page but does not return anything in $errors .