All Questions

Tagged with
Filter by
Sorted by
Tagged with
578 votes
5 answers
202k views

How should a model be structured in MVC? [closed]

I am just getting a grasp on the MVC framework and I often wonder how much code should go in the model. I tend to have a data access class that has methods like this: public function CheckUsername($...
Dietpixel's user avatar
  • 10.1k
294 votes
13 answers
114k views

Doctrine2: Best way to handle many-to-many with extra columns in reference table

I'm wondering what's the best, the cleanest and the most simply way to work with many-to-many relations in Doctrine2. Let's assume that we've got an album like Master of Puppets by Metallica with ...
Crozin's user avatar
  • 44.2k
114 votes
9 answers
251k views

Eloquent ORM laravel 5 Get Array of ids

I'm using Eloquent ORM laravel 5.1, and I want to return an array of ids greater than 0, my model is called test. I have tried : $test=test::select('id')->where('id' ,'>' ,0)->get()->...
paranoid's user avatar
  • 7,009
70 votes
5 answers
33k views

DDD and MVC: Difference between 'Model' and 'Entity'

I'm seriously confused about the concept of the 'Model' in MVC. Most frameworks that exist today put the Model between the Controller and the database, and the Model almost acts like a database ...
Nathan Loding's user avatar
67 votes
9 answers
91k views

How I can put composite keys in models in Laravel 5?

I have in my DataBase a table with two primary keys (id and language_id) and I need put it in my models. The default primaryKey in Models (Model.php in Laravel 5) is id, and I want that the ...
Sergioh Lonet's user avatar
61 votes
14 answers
72k views

PHPStorm is not recognizing methods of my Model class in Laravel 5.0 [duplicate]

failed insert data into database, and all query class and Model class's method not found show in IDE (phpStrom) how can I solve it? here is my extended class (Post.php) here show error in latest and ...
Osman Goni Nahid's user avatar
59 votes
5 answers
92k views

How to set a default attribute value for a Laravel / Eloquent model?

If I try declaring a property, like this: public $quantity = 9; ...it doesn't work, because it is not considered an "attribute", but merely a property of the model class. Not only this, but also I ...
J. Bruni's user avatar
  • 20.4k
57 votes
7 answers
185k views

Class 'App\Http\Controllers\DB' not found and I also cannot use a new Model

I have very basic problem. In L4 thes below methods worked out of the box, so now I am lost. Please help. A few days ago I started a Laravel 5.0 project. I have now fresh, clean installation. Problem ...
Peter's user avatar
  • 2,692
57 votes
8 answers
132k views

How to delete a model using php artisan?

Is there a command to safely delete a model in Laravel 5? To create a model we use php artisan make:model modelname And that will create a model under app folder, and also a migration in database/...
Jonathan Solorzano's user avatar
47 votes
16 answers
187k views

CodeIgniter PHP Model Access "Unable to locate the model you have specified"

I have been trying to load some models for this website I am building. However, for an unknown reason, it will bring the following error : An Error Was Encountered Unable to locate the model you ...
Alexandre Bolduc's user avatar
47 votes
4 answers
107k views

Check if laravel model got saved or query got executed

I've seen alot of people using this way to check if a laravel model got saved. So now I wonder if it is a safe way. And also can I check if the queries bellow got executed like this Check if model ...
user2722667's user avatar
  • 8,495
46 votes
6 answers
55k views

Magento - Passing data between a controller and a block

Really quick and simple question but I can't find a decent answer to this - What is the best way to pass data from a controller to a block in Magento. Incase it makes a difference, I am loading the ...
Drew Hunter's user avatar
  • 10.1k
37 votes
6 answers
97k views

Get Laravel Models with All Attributes

Is there a way to retrieve a model in Laravel with all the attributes, even if they're null? It seems to only return a model with the attributes that aren't null. The reason for this is that I have a ...
kenshin9's user avatar
  • 2,295
36 votes
7 answers
49k views

In Laravel, how do I retrieve a random user_id from the Users table for Model Factory seeding data generation?

Currently, in my ModelFactory.php, I have: $factory->define(App\Reply::class, function (Faker\Generator $faker) { return [ 'thread_id' => 1, 'user_id' => 1, 'body' => $faker-...
Simon Suh's user avatar
  • 10.7k
36 votes
1 answer
6k views

Best approach to model validation in PHP? [closed]

I've learned that there are often many ways to solve one programming problem, each approach typically having its own benefits and negative side affects. What I'm trying to determine today is the best ...
Jonathan's user avatar
  • 18.7k
34 votes
11 answers
43k views

Models in the Zend Framework

What are some of the ways you have implemented models in the Zend Framework? I have seen the basic class User extends Zend_Db_Table_Abstract and then putting calls to that in your controllers: $foo ...
rg88's user avatar
  • 20.8k
34 votes
4 answers
32k views

Kohana 3: Example of model with validation

I find examples and tutorials about models and about validation. And I places that say the validation (or most of it at least) should be in the model, which I agree with. But I can't any examples or ...
Svish's user avatar
  • 155k
33 votes
6 answers
49k views

Laravel 5 Models Folder

I have a directory called models inside app/ where I place all my model classes. Now I want to change the directory where the following command outputs the generated classes php artisan make:model ...
Alan's user avatar
  • 2,609
31 votes
5 answers
111k views

Laravel how to add a custom function in an Eloquent model?

I have a Product model class Product extends Model { ... public function prices() { return $this->hasMany('App\Price'); } ... } I want to add a function which will ...
Harrison's user avatar
  • 2,630
31 votes
6 answers
22k views

Laravel models: Where are model properties?

(I come from Visual Studio + Entity Framework background and trying to locate equivalent functionality in Laravel + Eloquent) In EF and Visual Studio, we add a new Model to our application and just ...
dotNET's user avatar
  • 34.4k
25 votes
2 answers
19k views

How to move the laravel 5.1 User model to \App\Models\User?

Is it possible to tell Laravel that I have moved the User.php model? Laravel 5.1 FatalErrorException in EloquentUserProvider.php line 126: Class '\App\User' not found I really wasn't keen on ...
user avatar
24 votes
2 answers
4k views

Magento Proper Way To Reindex Single Item and associated Group product

What is the proper way to reindex a single item after modifications have been made to it. Example context: Our company relies on a third party inventory management platform called Stone Edge. We ...
ajameswolf's user avatar
  • 1,650
23 votes
2 answers
15k views

Yii: validation rules that always apply except one scenario

I know that you can have a validation rule that applies only for one scenario: array('username', 'exist', 'on' => 'update'), Now i would like to know if it's possible to do the opposite: a rule ...
darkheir's user avatar
  • 8,900
21 votes
2 answers
5k views

How to determine if a table relationship is bidirectional or unidirectional in Doctrine 2?

I am in the process of upgrading from Doctrine 1.1.4 to Doctrine 2.0.6 in my Zend application. Currently, I am working on mapping the associations between entities. In Doctrine 2's Documentation it ...
Mr B's user avatar
  • 4,090
20 votes
4 answers
22k views

Can you access a model from inside another model in CodeIgniter?

I am writing a webapp using CodeIgniter that requires authentication. I created a model which handles all my authentication. However, I can't find a way to access this authentication model from inside ...
Eldila's user avatar
  • 15.6k
20 votes
5 answers
14k views

Modeling objects with multiple table relationships in Zend Framework

I'm toying with Zend Framework and trying to use the "QuickStart" guide against a website I'm making just to see how the process would work. Forgive me if this answer is obvious, hopefully someone ...
Andy Baird's user avatar
  • 6,120
18 votes
4 answers
13k views

Laravel: Does every table need a model?

I am building an occasion system with Laravel. I have several tables like: occasions occasion_categories (cars, trikes and other) Now i have a model called Occasion which represents the table ...
user3527894's user avatar
16 votes
5 answers
26k views

How to use multiple databases dynamically for one model in CakePHP

Ok, my first question was modified so many times that I chose to delete it and reformulate my question. I've made a small test-case project with different model-names to find a proper solution for my ...
Ariaan's user avatar
  • 1,106
16 votes
6 answers
36k views

How to validate email and email already exist or not check, in Yii Framework?

How to validate email using Yii Model validation rules function code. Also how to check email exist or not using Model validation rules function in Yii.
george's user avatar
  • 201
16 votes
1 answer
4k views

What are the differences between Joomla Model Types?

I'm trying to get to grips with the power behind Joomla (3.x)'s framework. I've noticed that there are multiple types of model that can be used in a component: JModelAdmin Prototype admin model. Acts ...
Sean's user avatar
  • 2,298
16 votes
3 answers
3k views

Why laravel model duplicates set of data and how (if possible) to have only one set of data?

It is convenient that laravel model provides a method that it can return results from another associated table. For example, I have a table called item and another table called feedback, where the ...
cytsunny's user avatar
  • 4,900
15 votes
4 answers
36k views

How to get fillable variable as array in laravel 4.2

When we create any Model class we create protected variable fillable I use this like $model = new Demo; $model->fillable // but now working $model->fillable() // but now working. Actually i ...
user avatar
15 votes
3 answers
33k views

CakePHP 3 Raw SQL Query

I'm using CakePHP 3, I need to run a raw SQL query on multiple tables. In CakePHP 2, this could be done by using the query() method on any model ( $this->Messages->query("select..") ). I need ...
Ananth's user avatar
  • 4,317
15 votes
1 answer
15k views

Backbone.js model.destroy() not sending DELETE request

I've been trying for days to get this working and I just cannot figure out why when I have my view to destroy a model which belongs to a collection (which properly has a url attribute for the ...
oz.'s user avatar
  • 151
15 votes
3 answers
1k views

Implementing a S.O.L.I.D Domain Object Model in the following project

I have the following example in which I tend to use a couple of classes, to create a simple web app. The file hierarchy seems like this. > cupid - libs - request - router ...
samayo's user avatar
  • 16.3k
15 votes
2 answers
12k views

cakephp one form, multiple models, not displaying one model's validation messages

I have a registration form and I am creating a record in both User and Identity tables (a user hasMany identities) the form looks like this <?php echo $this->Form->create('User');?> &...
Elwhis's user avatar
  • 1,241
14 votes
3 answers
26k views

Yii2 before save check if attributes are changed

I want to check if some attributes in my model are changed in beforeSave() method according to data stored in database. Is there some best practice to check if model has changed? My goal si to make ...
Aleš's user avatar
  • 783
14 votes
1 answer
6k views

PHP Domain Models, DAO, and how to implement

As I asked a question about singular/plural model naming conventions yesterday, I encountered the concept of a Domain Model. As I understand it so far, a Domain Model is simply an object which ...
ineedhelp's user avatar
  • 213
14 votes
1 answer
16k views

Laravel what is use HasFactory?

I created a model in Laravel. I always noticed the default would be use HasFactory. May I know what exactly does it work. In my understanding from reading documentation, it is for linking to database (...
Unkown Kid's user avatar
14 votes
2 answers
2k views

How to share a Symfony2 model with several projects

We are creating a SaaS that monitors certain assets. This means it takes in data, saves it, and displays it in a webinterface. For this, we have a few components that we created with/are moving to ...
Dieter's user avatar
  • 1,710
13 votes
2 answers
23k views

Laravel eloquent: Update A Model And its Relationships

With an eloquent model you can update data simply by calling $model->update( $data ); But unfortunately this does not update the relationships. If you want to update the relationships too you ...
user3518571's user avatar
13 votes
2 answers
7k views

The difference between an Eloquent Model and a Model?

So, i'm confused with this : In Laravel's official documentation, they say : The Eloquent ORM included with Laravel provides a beautiful, simple ActiveRecord implementation for working with your ...
elarib's user avatar
  • 674
13 votes
5 answers
42k views

Laravel model Trailing Data when save the model [duplicate]

I have some code like this $editStuState = StuAtt::where('studentId' , '=' , $id)->first(); $editStuState -> leave +=1; $editStuState -> present = $editStuState -> present-1; ...
Nasser Ali Karimi's user avatar
12 votes
9 answers
25k views

Yii form model validation- either one is required

I have two fields on the form ( forgotpassword form ) username and email Id . User should enter one of them . I mean to retrieve the password user can enter user name or the email id . Could some ...
Bujji's user avatar
  • 1,717
12 votes
2 answers
24k views

How to convert model data objects array to dataProvider

Suppose I have model User which have many to many relation to itself named as friends. so $user->friends (or $model->friends in view) gives me an array of User objects. I wanted to display the ...
Prashanth Shyamprasad's user avatar
12 votes
2 answers
10k views

CakePHP Model: COUNT(*) in Containable

I have a CakePHP 1.3 app and really enjoy the Containable behavior for fetching data. Let's assume I have Posts in one-to-many relationship with Comments. I use Containable to query (for pagination) ...
sibidiba's user avatar
  • 6,290
12 votes
5 answers
7k views

Difference between Controller and Model in MVC

I'm little confused about controller and model in MVC framework (codeIgniter). Its clear to me that controller methods calls the views and Model methods interact with database. However, I'm little ...
Roman's user avatar
  • 3,749
11 votes
13 answers
81k views

Unable to locate the specified class: Session.php in Codeigniter

The browser: Unable to locate the specified class: Session.php This is my Controller: <?php class Chat extends CI_Controller { public function __construct() { parent::__construct(...
thais's user avatar
  • 133
11 votes
3 answers
11k views

Magento model won't save values

I'm working on a backend module that saves to a custom table. My problem is that I've added fields to this table as I've been working on it, the newly added fields won't save with the model ->Save() ...
Christoffer Bubach's user avatar
11 votes
2 answers
30k views

How to update only specific fields of an active record in Yii?

I have a model (ActiveRecord) that has 5 properties (DB columns). I fetch a specific record and populate a form that has 3 fields (two other fields shouldn't be updated). Then I change a specific ...
lvil's user avatar
  • 4,326

1
2 3 4 5
42