Skip to main content
Rollback to Revision 3
Source Link
200_success
  • 144.2k
  • 22
  • 188
  • 473
namespace App\Http\Controllers\Website\SportsType;
use App\Classes\Contract\SportsType\ISportsType;
use \App\Http\Requests\SportsType\SportsTypeRequest as SportsTypeRequest;
class SportsTypeController extends \App\Http\Controllers\BaseController
{
    private $AllSportsTypes = "SportsTypes";
    private $sportstype;

    public function __construct(ISportsType $_sportstype) {
        $this->sportstype = $_sportstype;
        parent::__construct();
    }
    
    public function index() {
        $SportsTypes = $this->sportstype->All();
        return view('SportsType.List')->with('SportsTypes', $SportsTypes);
    }
    
    public function create() {
        return view('SportsType.Create');
    }
    
    public function edit($SportsTypeID) {
        
        $SportsType = $this->sportstype->Get($SportsTypeID);
        return view('SportsType.Edit', array('SportsType' => $SportsType));
    }
    
    public function save(SportsTypeRequest $request) {
        $data = [
            'SportsType'    =>  $request['SportsType'],
            'SportsTypeID'  =>  $request['SportsTypeID'],
        ];
        $result = $this->sportstype->Save($data);
        return redirect()->route($this->AllSportsTypes);
    }
}
namespace App\Classes\BusinessLogic\SportsType;
use App\Classes\DatabaseLayer\SportsType\SportsTypeDb;
use App\Classes\Contract\SportsType\ISportsType;

class SportsTypeBL implements ISportsType {       
    
    public function All() {
        $SportsTypes = (new SportsTypeDb())->All();
        return $SportsTypes;
    }
    
    public function Get($SportsTypeID) {
        $SportsType = (new SportsTypeDb())->Get($SportsTypeID);
        if($SportsType == null) {
            \App::abort(404);
            return;
        }
        return $SportsType;
    }
    
    public function Save($data) {
        return (new SportsTypeDb())->Save($data);
    }
}
namespace App\Classes\DatabaseLayer\SportsType;

class SportsTypeDb {
    
    public function All() {
        $SportsTypes = \App\Models\SportsType\SportsTypeModel::all();
        return $SportsTypes;
    }
}    

Interface

    public interfacefunction ISportsTypeGet($SportsTypeID) {
        $SportsType = \App\Models\SportsType\SportsTypeModel
                ::where('SportsTypeID', $SportsTypeID)
                ->first();
        return $SportsType;
    }
    
    public function AllSave($data) {
        if($data["SportsTypeID"] == 0) {
            $SportsType = new \App\Models\SportsType\SportsTypeModel();
        }
        else {
            $SportsType = $this->Get($data["SportsTypeID"]);
        }
        
        $SportsType->SportsType     = $data["SportsType"];
        $SportsType->save();
        return true;
    }
}

Am I writing bad or very bad code? Can you please suggest good ways to improve it?

  1. Which class should have code for caching?
  2. Am I writing bad or very bad code? Can you please suggest good ways to improve it?
class SportsTypeController extends \App\Http\Controllers\BaseController
{
    private $AllSportsTypes = "SportsTypes";
    private $sportstype;

    public function __construct(ISportsType $_sportstype) {
        $this->sportstype = $_sportstype;
        parent::__construct();
    }
    
    public function index() {
        $SportsTypes = $this->sportstype->All();
        return view('SportsType.List')->with('SportsTypes', $SportsTypes);
    }
}
class SportsTypeBL implements ISportsType {       
    
    public function All() {
        $SportsTypes = (new SportsTypeDb())->All();
        return $SportsTypes;
    }
}
class SportsTypeDb {
    
    public function All() {
        $SportsTypes = \App\Models\SportsType\SportsTypeModel::all();
        return $SportsTypes;
    }
}

Interface

public interface ISportsType {
     public function All();
}

Am I writing bad or very bad code? Can you please suggest good ways to improve it?

namespace App\Http\Controllers\Website\SportsType;
use App\Classes\Contract\SportsType\ISportsType;
use \App\Http\Requests\SportsType\SportsTypeRequest as SportsTypeRequest;
class SportsTypeController extends \App\Http\Controllers\BaseController
{
    private $AllSportsTypes = "SportsTypes";
    private $sportstype;

    public function __construct(ISportsType $_sportstype) {
        $this->sportstype = $_sportstype;
        parent::__construct();
    }
    
    public function index() {
        $SportsTypes = $this->sportstype->All();
        return view('SportsType.List')->with('SportsTypes', $SportsTypes);
    }
    
    public function create() {
        return view('SportsType.Create');
    }
    
    public function edit($SportsTypeID) {
        
        $SportsType = $this->sportstype->Get($SportsTypeID);
        return view('SportsType.Edit', array('SportsType' => $SportsType));
    }
    
    public function save(SportsTypeRequest $request) {
        $data = [
            'SportsType'    =>  $request['SportsType'],
            'SportsTypeID'  =>  $request['SportsTypeID'],
        ];
        $result = $this->sportstype->Save($data);
        return redirect()->route($this->AllSportsTypes);
    }
}
namespace App\Classes\BusinessLogic\SportsType;
use App\Classes\DatabaseLayer\SportsType\SportsTypeDb;
use App\Classes\Contract\SportsType\ISportsType;

class SportsTypeBL implements ISportsType {       
    
    public function All() {
        $SportsTypes = (new SportsTypeDb())->All();
        return $SportsTypes;
    }
    
    public function Get($SportsTypeID) {
        $SportsType = (new SportsTypeDb())->Get($SportsTypeID);
        if($SportsType == null) {
            \App::abort(404);
            return;
        }
        return $SportsType;
    }
    
    public function Save($data) {
        return (new SportsTypeDb())->Save($data);
    }
}
namespace App\Classes\DatabaseLayer\SportsType;

class SportsTypeDb {
    
    public function All() {
        $SportsTypes = \App\Models\SportsType\SportsTypeModel::all();
        return $SportsTypes;
    }
    
    public function Get($SportsTypeID) {
        $SportsType = \App\Models\SportsType\SportsTypeModel
                ::where('SportsTypeID', $SportsTypeID)
                ->first();
        return $SportsType;
    }
    
    public function Save($data) {
        if($data["SportsTypeID"] == 0) {
            $SportsType = new \App\Models\SportsType\SportsTypeModel();
        }
        else {
            $SportsType = $this->Get($data["SportsTypeID"]);
        }
        
        $SportsType->SportsType     = $data["SportsType"];
        $SportsType->save();
        return true;
    }
}
  1. Which class should have code for caching?
  2. Am I writing bad or very bad code? Can you please suggest good ways to improve it?
deleted 2154 characters in body
Source Link
Pankaj
  • 117
  • 9
namespace App\Http\Controllers\Website\SportsType;
use App\Classes\Contract\SportsType\ISportsType;
use \App\Http\Requests\SportsType\SportsTypeRequest as SportsTypeRequest;
class SportsTypeController extends \App\Http\Controllers\BaseController
{
    private $AllSportsTypes = "SportsTypes";
    private $sportstype;

    public function __construct(ISportsType $_sportstype) {
        $this->sportstype = $_sportstype;
        parent::__construct();
    }
    
    public function index() {
        $SportsTypes = $this->sportstype->All();
        return view('SportsType.List')->with('SportsTypes', $SportsTypes);
    }
    
    public function create() {
        return view('SportsType.Create');
    }
    
    public function edit($SportsTypeID) {
        
        $SportsType = $this->sportstype->Get($SportsTypeID);
        return view('SportsType.Edit', array('SportsType' => $SportsType));
    }
    
    public function save(SportsTypeRequest $request) {
        $data = [
            'SportsType'    =>  $request['SportsType'],
            'SportsTypeID'  =>  $request['SportsTypeID'],
        ];
        $result = $this->sportstype->Save($data);
        return redirect()->route($this->AllSportsTypes);
    }
}
namespace App\Classes\BusinessLogic\SportsType;
use App\Classes\DatabaseLayer\SportsType\SportsTypeDb;
use App\Classes\Contract\SportsType\ISportsType;

class SportsTypeBL implements ISportsType {       
    
    public function All() {
        $SportsTypes = (new SportsTypeDb())->All();
        return $SportsTypes;
    }
    
    public function Get($SportsTypeID) {
        $SportsType = (new SportsTypeDb())->Get($SportsTypeID);
        if($SportsType == null) {
            \App::abort(404);
            return;
        }
        return $SportsType;
    }
    
    public function Save($data) {
        return (new SportsTypeDb())->Save($data);
    }
}
namespace App\Classes\DatabaseLayer\SportsType;

class SportsTypeDb {
    
    public function All() {
        $SportsTypes = \App\Models\SportsType\SportsTypeModel::all();
        return $SportsTypes;
    }
    }
    

Interface

public functioninterface Get($SportsTypeID)ISportsType {
        $SportsType = \App\Models\SportsType\SportsTypeModel
                ::where('SportsTypeID', $SportsTypeID)
                ->first();
        return $SportsType;
    }
    
    public function Save($data) {
        if($data["SportsTypeID"] == 0) {
            $SportsType = new \App\Models\SportsType\SportsTypeModel();
        }
        else {
            $SportsType = $this->Get($data["SportsTypeID"]);
        }
        
        $SportsType->SportsType     = $data["SportsType"];
        $SportsType->saveAll();
        return true;
    }
}
  1. Which class should have code for caching?
  2. Am I writing bad or very bad code? Can you please suggest good ways to improve it?

Am I writing bad or very bad code? Can you please suggest good ways to improve it?

namespace App\Http\Controllers\Website\SportsType;
use App\Classes\Contract\SportsType\ISportsType;
use \App\Http\Requests\SportsType\SportsTypeRequest as SportsTypeRequest;
class SportsTypeController extends \App\Http\Controllers\BaseController
{
    private $AllSportsTypes = "SportsTypes";
    private $sportstype;

    public function __construct(ISportsType $_sportstype) {
        $this->sportstype = $_sportstype;
        parent::__construct();
    }
    
    public function index() {
        $SportsTypes = $this->sportstype->All();
        return view('SportsType.List')->with('SportsTypes', $SportsTypes);
    }
    
    public function create() {
        return view('SportsType.Create');
    }
    
    public function edit($SportsTypeID) {
        
        $SportsType = $this->sportstype->Get($SportsTypeID);
        return view('SportsType.Edit', array('SportsType' => $SportsType));
    }
    
    public function save(SportsTypeRequest $request) {
        $data = [
            'SportsType'    =>  $request['SportsType'],
            'SportsTypeID'  =>  $request['SportsTypeID'],
        ];
        $result = $this->sportstype->Save($data);
        return redirect()->route($this->AllSportsTypes);
    }
}
namespace App\Classes\BusinessLogic\SportsType;
use App\Classes\DatabaseLayer\SportsType\SportsTypeDb;
use App\Classes\Contract\SportsType\ISportsType;

class SportsTypeBL implements ISportsType {       
    
    public function All() {
        $SportsTypes = (new SportsTypeDb())->All();
        return $SportsTypes;
    }
    
    public function Get($SportsTypeID) {
        $SportsType = (new SportsTypeDb())->Get($SportsTypeID);
        if($SportsType == null) {
            \App::abort(404);
            return;
        }
        return $SportsType;
    }
    
    public function Save($data) {
        return (new SportsTypeDb())->Save($data);
    }
}
namespace App\Classes\DatabaseLayer\SportsType;

class SportsTypeDb {
    
    public function All() {
        $SportsTypes = \App\Models\SportsType\SportsTypeModel::all();
        return $SportsTypes;
    }
    
    public function Get($SportsTypeID) {
        $SportsType = \App\Models\SportsType\SportsTypeModel
                ::where('SportsTypeID', $SportsTypeID)
                ->first();
        return $SportsType;
    }
    
    public function Save($data) {
        if($data["SportsTypeID"] == 0) {
            $SportsType = new \App\Models\SportsType\SportsTypeModel();
        }
        else {
            $SportsType = $this->Get($data["SportsTypeID"]);
        }
        
        $SportsType->SportsType     = $data["SportsType"];
        $SportsType->save();
        return true;
    }
}
  1. Which class should have code for caching?
  2. Am I writing bad or very bad code? Can you please suggest good ways to improve it?
class SportsTypeController extends \App\Http\Controllers\BaseController
{
    private $AllSportsTypes = "SportsTypes";
    private $sportstype;

    public function __construct(ISportsType $_sportstype) {
        $this->sportstype = $_sportstype;
        parent::__construct();
    }
    
    public function index() {
        $SportsTypes = $this->sportstype->All();
        return view('SportsType.List')->with('SportsTypes', $SportsTypes);
    }
}
class SportsTypeBL implements ISportsType {       
    
    public function All() {
        $SportsTypes = (new SportsTypeDb())->All();
        return $SportsTypes;
    }
}
class SportsTypeDb {
    
    public function All() {
        $SportsTypes = \App\Models\SportsType\SportsTypeModel::all();
        return $SportsTypes;
    }
}

Interface

public interface ISportsType {
     public function All();
}

Am I writing bad or very bad code? Can you please suggest good ways to improve it?

Notice removed Draw attention by CommunityBot
Bounty Ended with no winning answer by CommunityBot
Notice added Draw attention by Pankaj
Bounty Started worth 50 reputation by Pankaj
deleted 82 characters in body
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

Question

In the below code.

  1. Which class should have code for Caching?
  2. Am I writing bad or very bad code? Can you please suggest good things to improve it?

My ControllerController class is below.

Business Logiclogic class is below.

Database class is like below

  1. Which class should have code for caching?
  2. Am I writing bad or very bad code? Can you please suggest good ways to improve it?

Question

In the below code.

  1. Which class should have code for Caching?
  2. Am I writing bad or very bad code? Can you please suggest good things to improve it?

My Controller class is below.

Business Logic class is below.

Database class is like below

Controller class

Business logic class

Database class

  1. Which class should have code for caching?
  2. Am I writing bad or very bad code? Can you please suggest good ways to improve it?
Post Undeleted by Pankaj
Post Deleted by Pankaj
edited title
Link
Pankaj
  • 117
  • 9
Loading
Source Link
Pankaj
  • 117
  • 9
Loading