[Solved] Removing eval from PHP function [closed]

It seems like you could simplify your code a lot, and remove the need for eval() which you shouldn’t use unless it is a last resort. There is no need for all the IF blocks had in your code, because if the value isn’t set, it also won’t be added to the $values array. Just … Read more

[Solved] Writing a function in laravel

You’re really missing out on the best parts of Laravel’s query builder. public function jobsearch(Request $request) { // htmlspecialchars makes no sense here $keyword = $request->input(‘keyword’); $city_id = $request->input(‘city_id’); $category_id = $request->input(‘category_id’); $query = DB::table(‘job_details’); if($keyword) { $query->where(‘job_title’, ‘like’, ‘%’.$keyword.’%’); } if($city_id) { $query->where(‘city_id’, $city_id); } if($category_id) { $query->where(‘category_id’, $category_id); } $results = $query->get(); foreach($data … Read more

[Solved] Sum array values of the same product

You can do this using groupBy and map functions of Laravel’s Collection: $collection = new \Illuminate\Support\Collection($array); $group = $collection->groupBy(‘product_id’); $resultArray = $group->map(function($item, $key) { return [ ‘total_size’ => $item->sum(‘comp_size’), ‘product_id’ => $key, ]; }); This will let you expand the code a bit easier in the future. 1 solved Sum array values of the same … Read more

[Solved] sql select in table grammage

using laravel database builder: $weight = DB::table(‘weight’)->where(‘grammage’, ‘150’)->first(); echo $weight->price; https://laravel.com/docs/5.5/queries#selects solved sql select in table grammage

[Solved] laravel/framework 9.x-dev requires php ^8.0 -> your PHP version (7.4.13) does not satisfy that requirement [closed]

Composer is telling you what is wrong. It wants PHP8 and you offer php7.4, so it doesnt install. From the comments it also says that laravel 9 is in development. As you’re stuggling with this, I dont recommend using that version and go one back, using 8. What I recommend doing (and what I’ve been … Read more

[Solved] How can show unlimited parent-child & sub-child tree data in laravel

you need to fetch all the products in one query and then process them to build the tree. You cant eager load it the traditional way. Original solution from Formatink public function products($projectId) { $products= Product::where(‘project_id’, $projectId)->get(); $products_by_id = collect(); foreach ($products as $product) { $products_by_id->put($product->id, $product); } foreach ($products as $key => $product) { … Read more

[Solved] Laravel withValidator() not working as expected

I’m an idiot and didn’t read the full doc. It needs to specify with an after function,like this: public function withValidator($factory) { $result = User::where(‘name’, $this->name)->get(); $factory->after(function ($factory) use ($result) { if (!$result->isEmpty()) { $factory->errors()->add(‘User’, ‘Something wrong with this guy’); } }); return $factory; } 1 solved Laravel withValidator() not working as expected

[Solved] ErrorException (E_ERROR) rawurlencode() expects parameter 1 to be string, object given ‘

This error message indicate that something is route with your url, in this case from the view. To solve this problem, this code <a href=”https://stackoverflow.com/questions/50911427/{{ url(“agent/edit_maintenance’, $maintenance }}” type=”button” class=”btn btn-outline btn-success”><i class=”ti-pencil”></i></a> as to change to <a href=”https://stackoverflow.com/questions/50911427/{{ url(“agent/edit_maintenance/’. $maintenance->id }}” type=”button” class=”btn btn-outline btn-success”><i class=”ti-pencil”></i></a> solved ErrorException (E_ERROR) rawurlencode() expects parameter 1 to … Read more