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']);





Thursday, 4 November 2021

Fill Menu items in partial view from database without using java script in C# ASP.NET MVC

 Fill Menu items in partial view from the database without using javascript in C# ASP.NET MVC.

Menu items from database


When there is a need to load menu items from the database, then you may have many options like load it from javascript. But the best load time is when you use Razor collaborate with C#. This post will help you to do the same. Follow the step-by-step instructions. I Guarantee that response time is the lowest than any other approach. 

Model

public class MenuModel

{

   public string ID { get; set; }

   public string MenuName { get; set; }

}

Saturday, 30 October 2021

Upload Laraver project to Godaddy Linux shared hosting using CPanel

 Follow the steps given below to upload your laravel project to Linux shared server with Cpanel in Godaddy.

Step 1:

 Move all files from public folder to your project root folder.