Category : php

Each Product can have several Category On each product page, I need to display 10 "related products". To that end, I would like to create a function on the Product model, that would return other products that have the most Category in common, and that would go like so: public function related_products() { return Product::with(‘categories’)->whereHas(‘categories’,function($query) ..

Read more

I am following a tutorial about Pagination in Laravel 8, But it did not work , this is what I have done : In BookingController.php public function index() { $bookings = DB::table(‘bookings’)->paginate(1); return view(‘bookings.index’) ->with(‘bookings’, $bookings); } In Booking.php class Booking extends Model { } In index.blade.php {{$bookings->links()}} It is not showing any error but ..

Read more

I’m trying to register a Persona and a User into the database with the Register.blade provided by Laravel 8 auth. This is the code that I have in the RegisterControlller in the create method $datos= [‘nombre’ => $data[‘name’],’apellido’ => $data[‘surname’],’cedula’ => $data[‘cedula’],’email’ => $data[’email’], ‘telefono’ =>$data[‘telefono’],’direccion’ =>$data[‘direccion’],’ciudadResi’ =>$data[‘ciudadResi’],’genero’ =>$data[‘genero’],]; var_dump($datos); Persona::create($datos)([ ‘nombre’ => $datos[‘nombre’], ‘apellido’ ..

Read more

I am working on shifting laravel 7.3 sessions to my native php file. By using the following code. try { require_once($_SERVER[‘DOCUMENT_ROOT’] . "/site/home/vendor/autoload.php"); require_once($_SERVER[‘DOCUMENT_ROOT’] . "/site/home/bootstrap/app.php"); $kernel = $app->make(‘IlluminateContractsHttpKernel’); $response = $kernel->handle($request = IlluminateHttpRequest::capture()); $base64_key = "base64:PujJyWOkF5GT0k9K3OU/hqh02v3x+7esupKXH31S1eI="; $payload = json_decode(base64_decode($app[‘config’][‘session.cookie’]), true); $iv = base64_decode($payload[‘iv’]); $key = base64_decode(substr($base64_key, 7)); $sessionId = openssl_decrypt($payload[‘value’], ‘AES-256-CBC’, $key, 0, $iv); ..

Read more

hi i use laravel mail for Newsletter it works but it takes a long time (more than 1 minutes) to send for more than 3 emails what should i do ? i use this code in article controller that when the status is active laravel send content of that article via email if($request->status == "active"){ ..

Read more

I want to resize my image and add white background but after running resizeCanvas method it is still the same. Where is the problem? I want to get a white-backgrounded 1000×1000 image but get a 1000×750 png $url = $record->original_image; $extension = pathinfo($url, PATHINFO_EXTENSION); $filename = $record->name.’.’. $extension; $file = file_get_contents($url); $directory = $record->image_folder_name.’/’.$filename; $originalImage ..

Read more

I am new in Laravel. I have a table, and that table name is {status}. Under the Models Status.php when I removed protected $table=’status’; from status.php then I am getting this error! IlluminateDatabaseQueryException SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘cms.statuses’ doesn’t exist (SQL: insert into statuses (status, user_id, updated_at, created_at) values (dfg, ..

Read more

I’ve been trying make my validation so that an extension must be unique to it’s own company but not to other companies. Here is my DB table: $table->id(); $table->foreignId(‘user_id’)->constrained(); $table->foreignId(‘account_id’)->constrained()->onDelete(‘cascade’); $table->string(‘first_name’)->nullable(); $table->string(‘last_name’)->nullable(); $table->string(’email’); $table->string(‘extension’); $table->string(‘password’)->nullable(); $table->string(‘user_type’)->default(‘user’); $table->timestamps(); $table->unique([‘extension’, ‘account_id’], ‘unique_extension’); And my validation rule looks like this: public function rules() { return [ ‘editExtension.first_name’ => ..

Read more

Changes I have made to user name registration do to client request we are using first name, middle name and last name in the user model I setup a function to bring them all into one. public function getFullNameAttribute($value) { return ucfirst($this->firstname) . ‘ ‘ . ucfirst($this->middle_name) . ‘ ‘ . ucfirst($this->lastname); } I am ..

Read more

I have built a Notification called OrderVerification.php and then added this to OrderController.php: use AppNotificationsOrderVerification; public function verify(Request $request, $id) { $order = Order::where(‘id’, $id)->update([‘status’ => ‘verified’]); $order->notify(new OrderVerification()); return redirect()->back(); } I also called the Notifiable and used IlluminateNotificationsNotifiable; at the Order.php Model. But when I test this, I get: Call to a member ..

Read more

On a fresh Laravel 8 installation I follow these steps: php artisan storage:link Inside /public/storage/ I create folder images/ and inside I paste an image called picture.png In web.php I define a route like this: Route::get(‘/picture’, function( return response()->file(Storage::url("images/picture.png")); )) However, if I visit this route in browser, the picture is not shown and the ..

Read more

I was browsing through the web and looking for solution on how can I modify this error message on Jetstream login: Inside app/Actions/Fortify there is a file CreateNewUser.php where I can put some validation custom message on each field like this: public function create(array $input) { Validator::make($input, [ ‘name’ => [‘required’, ‘string’, ‘max:255′], ’email’ => ..

Read more