Showing posts with label laravel Tutorial. Show all posts
Showing posts with label laravel Tutorial. Show all posts

Sunday, 14 November 2021

Layout/Master page in laravel

Layout/Master page in laravel

Making Layout or Master page in laravel is very simple . Go through the given steps below.

Step 1: Make a view named Layout.blade.php

Make a view for layout named layout.blade,php in resources\views folder.

Friday, 12 November 2021

User difined function Laravel

 We make user difined function to reuse code. To use user difined function you need to follow the steps
given below.

  • Make your file in app folder and write your code in that file . In my case file name is helper.php and funtion name is Title . i.e.
function Title()
{
   echo "Girfa IT Services";
}
  • Goto  composer.json file and add the following lines in autoload section.In my case pagelib.php is my file. Write your file name.
        "autoload": 
        {
        "files" :["app/pagelib.php"],
        },
  • Now you can call the function inside of helper.php  file , anywhere in your project.
Note : Run given command  for update your function

          composer dump-autoload 

Then, in your hosting site, you can update two files, autoload_classmap.php and autoload_static.php, manually in vendor/composer folder. I prefer to copy and paste the added classes from local to the hosting server

Save form data into database

 This post will help  step by step to understand , how to save your HTML form data into Mysql Database.

Database Table structure 


Form

Step 1

Make  HTML Form , code is given below

<form method="post" action="index">

    @csrf

    Name : <input type="text" name="name" placeholder="Your Name" required class="form-control"><br>

    Phone : <input type="text" name="phone" required placeholder="Phone Number" class="form-control"><br>

    Message :

    <textarea rows="5" name="message" required placeholder="Message" class="form-control"></textarea><br>

    <input type="submit" value="Save" name="submit">

</form>


Step 2 


Create Model by given command

php artisan make:model stumodel 

Model Location :  app\Models

Model Code

<?php

namespace App\Models;

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

class stumodel extends Model
{
protected $table = 'kashiquery';
    use HasFactory;
public $timestamps=false;
protected $fillable = [
'name', 'phone','message','createddate'
];
}

Step 3 : Create Controller


Create controller by given command below

Command : PHP artisan make:controller common

Controller location : app\Http\Controllers

Code

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\stumodel;
class common extends Controller
{
    public function AddData(Request $req)
{
        $data=new stumodel;
//$r = $req->input();
$data->name=$req["name"];
$data->phone=$req["phone"];
$data->message=$req["message"];
$data->createddate=date("Y-m-d");
$data->save();
return redirect('index');
    }
}
 

Step 4 : Configure Route


Route File Location : \routes\web.php 

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\common;


Route::get('/', function () {
    return view('index');
});
Route::view('index','index');
Route::post('index',[common::class,'AddData']);





Friday, 29 October 2021

Laravel command for beginners

 

Create and run project using composer

composer create-project laravel/laravel your-project-name

cd your-project-name

Goto project folder i.e your-project-name

php artisan serve

Next Topic