Category : model

I have following laravel model. When I try to visit the site it shows the following error. SymfonyComponentErrorHandlerErrorFatalError Type of AppModelsSetting::$fillable must not be defined (as in class IlluminateDatabaseEloquentModel) Environment information Laravel version: 8.60.0 PHP version: 7.4.16 <?php namespace AppModels; use IlluminateDatabaseEloquentFactoriesHasFactory; use IlluminateDatabaseEloquentModel; class Setting extends Model { use HasFactory; protected array $fillable = ..

Read more

I Don’t know where the mistake is the data is not saving into the database.Can any one help it will be use full for me. I am stuck on these for days. Thank you in advance. My Routes Route::get(‘/reject’,’[email protected]’); Route::post(‘/reject’,’[email protected]’); My Controller(RejectionReasonsController) <?php namespace AppHttpControllers; use IlluminateHttpRequest; class RejectionReasonsController extends Controller { public function index(){ ..

Read more

I got different result from getReward1 and getReward2: Model: class User extends Authenticatable { public function Products() { return $this->hasMany(‘AppProduct’, ‘user_id’); } public function getReward1() { return $this ->Products ->where(‘reward’, ‘>’, 0) ->where(‘status’, 0) ->sum(‘reward’); // sum = 7,690,000 } public function getReward2() { return $this ->Products() ->where(‘reward’, ‘>’, 0) ->where(‘status’, 0) ->sum(‘reward’); // sum ..

Read more

here is my code example, i think it’s descriptive, I already tried to pass an array of the model, User [], but it didn’t work <?php namespace AppModulesUsersRepositoriesUsersRepository; use AppModulesUsersModelsUser; use AppModulesUsersDtosICreateUserDTO; use ArrayObject; use IlluminateDatabaseEloquentCollection; use phpDocumentorReflectionTypesMixed_; interface IUsersRepository{ public function create(ICreateUserDTO $data): User; public function list(): User[]; } ?> Sourc..

Read more

As you can see that I am saving the array by using Save() function. Kindly someone add, is there any way by which I can store unique data. Thanks in advance public function store(array $mainNewsLinks): array { for ($i = 0; $i < count($mainNewsLinks); $i++) { $mainNews = new SectorMainNewsTable(); $mainNews->source_id = $this->sourceId; $mainNews->cluster_id = ..

Read more

Imagine you have a controller or some code that looks something like this: <?php namespace AppHttpControllers; use IlluminateHttpRequest; use IlluminateHttpJsonResponse; class TeamController { public function create(Request $request): JsonResponse { $request->validated(); $team = new Team([‘name’ => $request->get(‘name’)]); if (!$team->save()) { // some really important logic you want to cover // cover by a test. } … ..

Read more

So I was learning Laravel 8, and came across this problem. At that time I made 4 migrations and their models. When I run the command "php artisan migrate". Then a problem arose in the last migration. This is the 1st migration (2021_08_18_092502_create_masyarakats_table.php) <?php use IlluminateDatabaseMigrationsMigration; use IlluminateDatabaseSchemaBlueprint; use IlluminateSupportFacadesSchema; class CreateMasyarakatsTable extends Migration { ..

Read more

https://i.stack.imgur.com/daxZg.png <pre> DB::table("game") ->join("game_description", "game_description.game_id", "=", "game.game_id") ->where("game_description.language_id", "=", getLocaleID()) ->where("game_description.active", "=", 1) ->leftJoin("product_to_game", "product_to_game.game_id", "=", "game.game_id") ->leftJoin("product_price", "product_price.product_id", "=", "product_to_game.product_id") ->orderBy("product_price.product_price", "DESC"); </pre> I have to create a query like this (in eloquent model). I have to connect 6-7 tables in one query. Can you help me how can i do that? Sourc..

Read more

I created a new model named "WalletAddress", that have the following migration file: Schema::create(‘wallet_addresses’, function (Blueprint $table) { $table->bigIncrements(‘id’); $table->bigInteger(‘user_id’)->comment(‘User Owner of address’); $table->string(‘alias’)->comment(‘alias name for the address’); $table->string(‘type’)->comment(‘Address type’); $table->string(‘address’)->comment(‘Wallet Address’); $table->enum(‘status’,[ ‘Confirmed’, ‘Pending’, ‘Deleted’, ]); $table->json(‘address_properties’)->nullable(); $table->timestamps(); $table->softDeletes(); }); The Model class is defined as the following: class WalletAddress extends Model { use ..

Read more

I’m building a project with Laravel 8. I need to handle request parameter which contains page, limit, searchColumn, searchText, orderColumn and orderDirection. Sometimes I need to search in relations. I’ve built this system below but it doesn’t work on relationships. $query = (new Log())->newQuery(); $query->with(‘customer’, ‘domain’, ‘type’); if ($request->searchColumn != "" && $request->searchColumn != NULL) ..

Read more