mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-02-07 03:58:52 -06:00
--- Issue --- When you create a new group it never sets up any forums permissions for that group. This was causing errors like Trying to get property 'show_forum' of non-object ... This is due to in code its trying to access a property of a null object, this is fatal and cause the app to crash, this happens when the page tries and loads permissions for that group/forum and the groups permissions is a null object. --- Fix --- In the add() method of the Staff/GroupsController.php we create a permissions object for each forum and associate it to the new groups id. --- Views --- When using traditional form inputs and passing that data through the request object, you should name the inputs the same name as the database columns. This will make it easier in code to just pass the request data to the create/update operations. --- Models --- When using mass assignments like Model::create() and/or Model::update(), we have to tell the model to not guard those columns. So by adding `protected $guarded = ['id'];` to the Model we say Only guard the 'id'. Also, try and avoid the `Raw` eloquent queries! --- Controllers --- Validation rules should be in here and not in the Model and should be validated BEFORE the creation of the resource! --- Reminder --- The Model is strictly for interacting with the database. The Controller handles the http/ajax requests The View handles how to present the data to the users screen The Repository/Concrete Classes are to handle the application specific logic
52 lines
1.0 KiB
PHP
Executable File
52 lines
1.0 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* NOTICE OF LICENSE
|
|
*
|
|
* UNIT3D is open-sourced software licensed under the GNU General Public License v3.0
|
|
* The details is bundled with this project in the file LICENSE.txt.
|
|
*
|
|
* @project UNIT3D
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
|
|
* @author HDVinnie
|
|
*/
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Group extends Model
|
|
{
|
|
public $timestamps = false;
|
|
|
|
protected $guarded = ['id'];
|
|
|
|
/**
|
|
* Has many users
|
|
*
|
|
*/
|
|
public function users()
|
|
{
|
|
return $this->hasMany(\App\User::class);
|
|
}
|
|
|
|
/**
|
|
* Has many permissions
|
|
*
|
|
*/
|
|
public function permissions()
|
|
{
|
|
return $this->hasMany(\App\Permission::class);
|
|
}
|
|
|
|
/**
|
|
* Returns the requested row from the permissions table
|
|
*
|
|
*/
|
|
public function getPermissionsByForum($forum)
|
|
{
|
|
return Permission::where('forum_id', $forum->id)
|
|
->where('group_id', $this->id)
|
|
->first();
|
|
}
|
|
}
|