how to take custom amount of data from foreach loop php laravel

Advertisements So in Eloquent there is a take() and skip() functions works like this: $users = DB::table(‘users’)->skip(10)->take(5)->get(); But now I’m reading data from a json file: $path = storage_path() . "/app/public/userexam.json"; json_decode(file_get_contents($path), true); So after reading data, I want to use a foreach loop: foreach($json as $js){ … } But I do need to take… Read More how to take custom amount of data from foreach loop php laravel

Foreach loop does not add counter

Advertisements I have this custom foreach loop at Blade: <div id="dynamic_field"> @foreach($niloufars as $niloufar) @php $counter = 1; @endphp <div class="row"> <div class="col-md-6"> <div class="form-group"> <span class="text-danger force-required"></span> <label for="niloufar_name">Title</label> <input type="text" class="form-control" name="niloufar_name_{{ $counter }}" value="{{ $niloufar->name }}"> </div> </div> <div class="col-md-6"> <div class="form-group"> <span class="text-danger force-required"></span> <label for="niloufar_link">Link</label> <input type="text" class="form-control" name="niloufar_link_{{ $counter… Read More Foreach loop does not add counter

Ignoring the user result input when updating data goes wrong

Advertisements I’m working on an edit.blade.php where users can edit data and the update method of Controller goes here: public function update(Request $request, $id) { $discountCode = DiscountCode::find($id); $request->validate([ ‘code’ => ‘unique:discount_codes,code’.$discountCode->id, ‘started_at’ => ‘required_if:timespan,TRUE’, ‘ended_at’ => ‘required_if:timespan,TRUE’, ], … } So as you can see the code must be uique in discount_codes table. So… Read More Ignoring the user result input when updating data goes wrong

How to increase width and height of an iframe which is created tinymce editor

Advertisements I’m using Laravel 5.8 and TinyMCE and I have added an iframe to this editor and make a new post with it. Then at the Blade, I tried retrieving data like this: <!– News Content –> <div class="text-justify mt-3"> {!! $new->nws_description !!} </div> And it correctly shows the content but the only problem is… Read More How to increase width and height of an iframe which is created tinymce editor

Argument 1 passed, must be of the type array, string given

Advertisements I’m working with Laravel 5.8 and I made a page to see all uploaded files which are stored at the media_library table. And I get all the data like this: public function __construct(MediaLibraryRepository $mediaLibraryRepoObject) { $this->mediaLibraryRepoObject = $mediaLibraryRepoObject; } public function index() { $res = $this->mediaLibraryRepoObject->select(); $media = $res["media"]; $files = $res["files"]; $extensions =… Read More Argument 1 passed, must be of the type array, string given

"Syntax error or access violation" error while trying to join a table column multiple times

Advertisements I want to join 3 tables named members, students and baseinfos. And baseinfos holds some id as bas_id and name of it is stored in bas_value: And this is my code: $records = DB::table(‘members’) ->where(‘mys_olp_id’,4) ->join(‘students’, ‘members.mbr_usr_id’, ‘=’, ‘students.std_mbr_id’) ->join(‘baseinfos as gender’, ‘members.mbr_gender_id’, ‘=’, ‘gender.bas_id as gvalue’) ->join(‘baseinfos as degree’, ‘students.std_degree_id’, ‘=’, ‘degree.bas_id as… Read More "Syntax error or access violation" error while trying to join a table column multiple times

Not null violation: 7 ERROR: null value in column – Laravel 5.8

Advertisements I don’t understand this, I alter my table to add these columns Schema::table(‘clusters’, function($table) { $table->string(‘ssaEnabled’,1)->default(‘0’); $table->string(‘ssaBackendUrl’)->default(NULL); $table->string(‘ssaPortalApiUrl’)->default(NULL); }); in my store() I have this $cluster->ssaEnabled = Input::get(‘ssaEnabled’,’0′); $cluster->ssaBackendUrl = Input::get(‘ssaBackendUrl’,”); $cluster->ssaPortalApiUrl = Input::get(‘ssaPortalApiUrl’,”); $cluster->save(); I kept getting prod.ERROR: SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column "ssaBackendUrl" violates not-null constraint Why… Read More Not null violation: 7 ERROR: null value in column – Laravel 5.8

Weird Give Data Is Invalid Error Message While Trying To Update

Advertisements I have a Laravel 5.8 project and I have created this form for updating a title of a record: <form action="{{ route(‘popups.update’, [‘id’=>$popup->id]) }}" method="POST"> @csrf <label for="title" class="control-label">Title</label> <input type="text" id="title" name="title" class="form-control" value="{{ $popup->title }}"> <button class="btn btn-success" type="submit">Submit</button> </form> And this is the Controller method for updating: public function update(Request $request,… Read More Weird Give Data Is Invalid Error Message While Trying To Update

Console.log does not show result based on variable value

Advertisements I’m using Laravel 5.8 and in this project, I wanted to show some results in Javascript based on the variable which is sent to View. So at the Controller, I have added this: $title = ""; if($popup->showtitle == 1){ $title = $popup->title; } return view("frontend.home")->with(‘title’,$title); Then at the view: <script> var title = JSON.parse("{{… Read More Console.log does not show result based on variable value