Category : php

Laravel seems to have an opinionated way to do everything, but I can’t find any documentation on the "best practice" way to extended CRUD methods. Is there one? For example I have a series of steps I need to go through before I can persist a model. They’re steps that will always happen. I don’t ..

Read more

Not sure what I’m missing here, but nothing I do seems to allow @push(‘styles’) or @push (‘scripts’) to work. layout/app.blade.php includes: … @livewireStyles … @livewireScripts … livewire/tagify.blade.php @push(‘styles’) <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@yaireo/[email protected]/dist/tagify.min.css"> @endpush @push(‘scripts’) <script src="https://cdn.jsdelivr.net/npm/@yaireo/[email protected]/dist/tagify.min.js"></script> <script> document.addEventListener("DOMContentLoaded", function(event) { var input = document.getElementById(‘tagify’) var tagify = new Tagify(input, { whitelist : [ @foreach($tags as $tag) ..

Read more

I’ve written a query for checking the messages that are written to conversation after it’s deleted by a user that’s in conversation. Here is my query: $messages = DB::table(‘conversations’) ->where(‘conversations.id’, $conversation->id) ->join(‘messages’, ‘messages.conversation_id’, ‘=’, ‘conversations.id’) ->join(‘deleted_conversations’, ‘deleted_conversations.conversation_id’, ‘=’, ‘conversations.id’) ->where(‘messages.created_at’, ‘>=’, ‘deleted_conversations.created_at’) ->orderBy(‘messages.created_at’, ‘desc’) ->select(‘messages.*’) ->get() ->all(); But everytime i try to run this query ..

Read more

I have model ‘Transaction’ which represent a message to be send, and the transaction shall have a relationship called ‘recipients’, recipient might be a ‘Group’ Or a ‘Person’. What type of eloquent relationship should I used? How to implement that? Transaction: Schema::create(‘transactions’, function (Blueprint $table) { $table->id(); $table->enum(‘destination_type’, DestinationType::getValues()); $table->foreignId(‘user_id’)->constrained(‘users’); $table->timestamps(); }); Recipient: Schema::create(‘recipients’, function ..

Read more

In Controller: $user = user()->id; $tasks = task::with(‘user’)->where(‘tasks.user_id’, ‘=’, ‘$user’)->get(); Task Model: public function user() { return $this->belongsTo(User::class, ‘user_id’, ‘id’); } User Model: public function Tasks() { /** * The relationship to the user’s tasks. * * @return HasMany */ return $this->hasMany(Task::class, ‘user_id’, ‘id’); } Here is the error: Trying to get property ‘user_id’ of ..

Read more

I have a problem with shuffle. I have a 2 data (Test1,Test2) and I want to save it to database using shuffle but it’s always return same value it is not randomizing. Here is my code. $item = $data[9]; $str_arr = explode(",", $item);// item to search $collectKey = collect($str_arr); $iteratedData = $collectKey->shuffle(); foreach($iteratedData as $itr){ ..

Read more

Trying to find an ID from different models. My original table has a listing of the Tasks. However, task details are different so once added, it will be added to different Models/Tables. Code below will try to find a task_id from different models. As I need to view the details for that Task. But was ..

Read more

I have an object called Logo, there is a setter in this object for the layout: public function setLayout(string $layout): void { $this->layout = $layout; } I create an instance of Logo and then a loop of different layouts: $logo = new Logo($request->name, $font, $symbol); foreach (Logo::getConstants() as $layout) { $logo->setLayout($layout); $newLogo = new LogoMaker($logo); ..

Read more

I have some problems with checking if some value exists in database and if not then to create it and return id, but every time when I write something like: $attribute = AttributeValue::where(‘value’, $value)->firstOrCreate([ ‘value’ => $value, ‘attribute_id’ => $relation->attribute_id, ‘default_order’ => $next ]); It gives error for duplicate entry, like: PDOException: SQLSTATE[23000]: Integrity constraint ..

Read more

Having this simple calculator: /etc/apache2/sites-enabled/php.conf : <VirtualHost *:80> ServerName php DocumentRoot /var/www/php </VirtualHost> /var/www/php/laravel/test/app/Models/Calculator.php: <?php namespace AppModels; class Calculator { const ADD = 1, SUBTRACT = 2, MULTIPLY = 3, DIVIDE = 4; public function getOperations(): array { return [ self::ADD => ‘Scitani’, self::SUBTRACT => ‘Odcitani’, self::MULTIPLY => ‘Nasobeni’, self::DIVIDE => ‘Deleni’ ]; } public ..

Read more

I want to write custom from validation , but when I’m using custom validation in my store controller it gets me error the error is : InvalidArgumentException: Database connection [vendor] not configured. in file D:clodth_projectcloth_apivendorlaravelframeworksrcIlluminateDatabaseDatabaseManager.php on line 152 my validation class is : class StoreRequest extends FormRequest { /** * Determine if the user is ..

Read more

My images were working fine, but right now i have a problem with my storage directory. Before they were going here : But now they are going here : My code Profile Controller : if($r->hasFile(‘profile_avatar’)){ Auth::user()->update([ ‘profile_avatar’ => $r->profile_avatar->store(‘public/avatars’) ]); } if($r->hasFile(‘banner’)){ Auth::user()->profile()->update([ ‘banner’ => $r->banner->store(‘public/avatars’) ]); } Session::flash(‘success’, ‘Perfil Atualizado com Sucesso!’); return redirect()->back(); ..

Read more

I can make the request I want using cURL, but it’s failing when I try to replicate it using Laravel (returning 404). I’ve ensured the data being sent is identical. Here’s the cURL: curl –request POST –url https://www.api-provider.com/api/v2/access_keys –header ‘Authorization: Bearer 53d9814ed1385f44e6d5ed24979e11c2f7da654b40’ –header ‘Content-Type: application/json’ –data ‘{"access_key":{"key":"Lmy48Z0vA89","rate_ids":["[]"],"listing_id":"5de8f56797209ffbe","quantity":1,"is_active":true}}’ Here’s the Laravel equivalent (following Guzzle’s documentation): $response ..

Read more