dev-master
9999999-dev https://github.com/zahidgani/larashoppingBasic shopping cart system in laravel packages
MIT
The Requires
- php >=5.3.0
by Zahid Gani
Basic shopping cart system in laravel packages
Add service provider in yoiur src/ShoppingServiceProvider.php, (*1)
namespace laravelcms\shopping; use Illuminate\Support\ServiceProvider; class ShoppingServiceProvider extends ServiceProvider { public function boot() { include DIR.'/routes.php'; //For publich and copy this view in your another laravel project command:php artisan vendor:publish $this->publishes([ DIR.'/views' => base_path('resources/views/laravelcms/shopping'), ]);, (*2)
$this->publishes([ __DIR__ . '/migrations' => $this->app->databasePath() . '/migrations' ], 'migrations'); $this->publishes([ __DIR__ . '/seeds' => $this->app->databasePath() . '/seeds' ], 'seeds');
}, (*3)
public function register()
{
// register our controller
$this->app->make('laravelcms\shopping\ProductController');
$this->loadViewsFrom(DIR.'/views', 'add-product');
$this->loadViewsFrom(DIR.'/views', 'manage-product');
}
}, (*4)
Add controller in yoiur src/ProductController.php, (*5)
namespace laravelcms\shopping; use App\Http\Controllers\Controller; use Illuminate\Http\Request; use Illuminate\Support\Facades\Session; use laravelcms\shopping\models\Item; error_reporting(0); class ProductController extends Controller { public function form_product() {, (*6)
return view('add-product::add_product');
} public function form_submitted(Request $request) {, (*7)
$product_name = stripslashes($request->product_name); $product_amount = stripslashes($request->product_amount); $product_desc = stripslashes($request->product_desc); $date = date("Y-m-d h:i:s"); $stm=new Item; $stm->product_name=$product_name; $stm->product_amount=$product_amount; $stm->product_desc=$product_desc; $stm->created_at=$date; $stm->updated_at=$date; $stm->save(); //session()->flash('sussess', 'Successfully updated invoice price'); return redirect("manage-product");
} public function list_product() { $id=isset($_REQUEST["id"])?$_REQUEST["id"]:0; if($id>0) { Item::where("id",$id)->delete(); }, (*8)
$row=Item::all(); return view('manage-product::manage_product')->with("row",$row);
} }, (*9)
Add routes in src/routes.php Route::get("test","laravelcms\shopping\ProductController@index"); Route::get("add-product","laravelcms\shopping\ProductController@form_product"); Route::get("manage-product","laravelcms\shopping\ProductController@list_product"); Route::post("add-products","laravelcms\shopping\ProductController@form_submitted");, (*10)
Add views folder and add file in views it should be src/views/add_product.blade.php src/views/manage_product.blade.php, (*11)
again run: composer dump-autoload, (*12)
Add migration folder in src/migrations/2017_03_14_000000_create_product_demo_items_table.php use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration;, (*13)
class CreateProductDemoItemsTable extends Migration { public function up() { Schema::create('laracms_product', function(Blueprint $t) { $t->increments('id')->unsigned(); $t->string('product_name', 200); $t->string('product_amount', 10); $t->string('product_desc', 500); $t->timestamps(); }); }, (*14)
public function down() { Schema::drop('laracms_product'); }
}, (*15)
Add Models folder src/models/Items.php namespace laravelcms\shopping\models;, (*16)
use Illuminate\Database\Eloquent\Model;, (*17)
class Item extends Model { protected $table = 'laracms_product'; }, (*18)
==============if you want to reuse your code, (*19)
Basic shopping cart system in laravel packages
MIT