0% found this document useful (0 votes)
144 views4 pages

Laravel Pizza CRUD Commands Guide

The document provides information on Laravel commands, functions for CRUD operations, and code snippets for controllers, models, routes, and views for a pizza ordering application built with Laravel. It includes commands to initialize a new Laravel project, migrate databases, and generate models and controllers. Functions are shown for inserting, displaying, finding, updating, and selecting pizza records from the database. Blade templates display forms and record listings. The model defines the pizza table. Routes connect form submissions and function calls.

Uploaded by

Touleen Akoum
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
144 views4 pages

Laravel Pizza CRUD Commands Guide

The document provides information on Laravel commands, functions for CRUD operations, and code snippets for controllers, models, routes, and views for a pizza ordering application built with Laravel. It includes commands to initialize a new Laravel project, migrate databases, and generate models and controllers. Functions are shown for inserting, displaying, finding, updating, and selecting pizza records from the database. Blade templates display forms and record listings. The model defines the pizza table. Routes connect form submissions and function calls.

Uploaded by

Touleen Akoum
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Commands laravel:

Composer create-project --prefer-dist laravel/laravel final 2021


php artisan serve
php artisan make:migration create_users_table
php artisan migrate:refresh
php artisan migrate:reset
php artisan make:model Page
php artisan make:controller PagesController

->references('id')->on('users')

Function:
To insert:
    public function formInsert(){
        return view("01_form_insert");
    }

public function insert(){


            $objp  = new Pizza();
            $objp -> name = request('name');
            $objp -> type = request ('type');
            $objp -> base = request('base');
            $objp -> save();
            return redirect('/');
    }
To display all:
 public function all(){
        //1
       $arrPizza = Pizza::all();
        //echo "<pre>"; print_r ($arrPizza);
        //$rec = Pizza::OrderBy('name','desc')->get();
        //$arrPizza = Pizza::where('name','wissam')->get();
       return view ('display', ['record'=>$arrPizza]);
    }
To find someone:
public function show($id){
        $recPizza = Pizza::find($id);
        //$recPizza = Pizza::findOrFail($id);
       return view ('onepizza', ['pizza'=>$recPizza]);
       
    }
To update:
public function formUpdate(){
        return view("02_form_update");
    }
    public function update(){
        $objp  = new Pizza();
        $objp -> id = request('id');
        $objp -> name = request('name');        
        $objp -> type = request ('type');
        $objp -> base = request('base');
        //initialize VARs
        $id = $objp -> id;
        $name = $objp -> name;
        $type = $objp -> type;
        $base = $objp -> base;
        $objp = Pizza::where("id", $id)->update(["name" => $name, "type" =>
$type, "base" => $base]);  
        return redirect('/allpizza');
    }
To selectAll:
    public function selectAll(){
        $objp  = new Pizza();        
        $objp  =  Pizza::all();
        //echo "<pre>" ;print_r ($objp);
        return view ('selectALL', ['record'=>$objp]);      
 
      }

In Blade.php:
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Laravel</title>
        <!-- Fonts -->
        <link href="https://fonts.googleapis.com/css?family=Nunito:200,600"
rel="stylesheet">
        <!-- Styles -->
        <link href="/css/main.css" rel="stylesheet">
    </head>
    <body>

      <footer>
        <p>Copyright 2020 Pizza House</p>
      </footer>
    </body>
</html>
<?php
//echo "<pre>"; print_r ($arrPizza);
?>

@extends('layouts.HeaderFooter')
@section('content')
<div class="flex-center position-ref full-height">
    <div class="content">
        <img src="/img/pizza-house.png" alt="pizza house logo">
        <div class="title m-b-md">
            Here You can Display All pizzas
        </div>
        <!-- @foreach($record as $rec)
            {{$rec->type}} <?php /* echo "<br>"; */ ?>
            {{$rec->base}} <?php /* echo "<br>"; */ ?>
            {{$rec->name}} <?php /* echo "<br>"; */ ?>
        @endforeach -->

        @foreach($record as $rec)
            {{$rec->type}} --
            {{$rec->base}} --
            {{$rec->name}} --
            <?php echo "<br>"; ?>
        @endforeach
    </div>
</div>
@endsection

Form to insert:

<?php
//echo "welcome";?>
@extends('HeaderFooter')
@section('content')
    <div class="content">
        <img src="/img/pizza-house.png" alt="pizza house logo">
        <div class="title m-b-md">
            Here You can insert  just one pizzas
        </div>
    </div>
    <div class="wrapper create-pizza">
  <h1>Create a New Pizza</h1>
  <form action="/funcInsert" method="POST">
    @csrf
    <label for="name">Your name:</label>
    <input type="text" name="name" id="name" required>
    <label for="type">Choose type of pizza:</label>
    <select name="type" id="type">
      <option value="margarita">Margarita</option>
      <option value="hawaiian">Hawaiian</option>
      <option value="veg supreme">Veg Supreme</option>
      <option value="volcano">Volcano</option>
    </select>
    <label for="base">Choose crust:</label>
    <select name="base" id="base">
      <option value="thick">Thick</option>
      <option value="thin & crispy">Thin & Crispy</option>
      <option value="cheese crust">Cheese Crust</option>
      <option value="garlic crust">Garlic Crust</option>
    </select>    
    <input type="submit" value="Order Pizza">
  </form>
</div>
@endsection

In model:
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Pizza extends Model


{
    use HasFactory;
    public $table='pizzas';
}

In web.php:

Route::get('/form/rec', 'App\http\controllers\PizzaController@formInsert');
Route::Post('/funcInsert','App\http\controllers\PizzaController@insert');
Route::get('/allpizza', 'App\http\controllers\PizzaController@all');

You might also like