01.Create a laravel 5.4 projects composer create-project laravel/laravel AuthenticationLaravel “5.4.*” We can use larave 5.5 Details…
Tag: PHP
Generic Repository Pattern implementation with laravel
Create a database in mysql
1 2 3 4 5 |
drop table test; create table test( id int(11) AUTO_INCREMENT PRIMARY KEY, name text ); |
or create model by artisan command
1 |
php artisan make:model Test |
or create Details…
Add Menu in Drupal
1.To Add menu go to Structure->Menus->Add Menu (My First Menu) 2.Add links for pages 3.Show Details…
01.My Personal Introduction to Drupal
The standard release of Drupal, known as Drupal core, contains basic features that can be Details…
Modules in Yii2
Modules is replacement of folder structure in yii2 .Meaning no folder structure in controllers folder Details…
Ajax Form in Laravel with validation
//http://code4fun.io/post/laravel-ajax-register-and-login #view
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
<html lang="en"> <head> <title>Custom Validation Rule Laravel 5</title> <meta name="_token" content="{{ csrf_token() }}" /> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" > <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script> $.ajaxSetup({ headers: { 'X-CSRF-Token' : $('meta[name=_token]').attr('content') }, }) </script> </head> <body> <nav class="navbar navbar-default"> <div class="container-fluid"> <div class="navbar-header"> <a class="navbar-brand" href="#">Custom Validation Rule Laravel 5</a> </div> </div> </nav> <div class="container"> <form id='sign-up' action="{{ URL::to('customValiPost') }}" class="form-horizontal" method="post" novalidate> {{csrf_token()}} @if (count($errors) > 0) <div class="alert alert-danger"> <ul> @foreach ($errors->all() as $error) <li>{{ $error }}</li> @endforeach </ul> </div> @endif <!--<input type="text" name="title" class="form-control" style="width:30%" placeholder="Add Odd String" />--> <div class="form-group" id="email-div"> <label class="control-label" for="title">title</label> <input id="title" type="text" placeholder="example@gmail.com" title="Please enter you email" required value="" name="title" class="form-control"> <span class="help-block"> <strong id="form-errors-title"></strong> </span> <span class="help-block small">Your email</span> </div> </span> @if ($errors->has('title')) <span class="help-block"> <strong>{{ $errors->first('title') }}</strong> </span> @endif <br/> <button class="btn btn-primary">Save</button> </form> <script> $(function(){ $('#sign-up').on('submit',function(e){ $.ajaxSetup({ headers: { 'X-CSRF-Token' : $('meta[name=_token]').attr('content') }, }) e.preventDefault(e); $("#title-div").removeClass("has-error"); $.ajax({ type:"POST", url:'/laravel1/public/ajax', data:$(this).serialize(), //dataType: 'json', success: function(data){ console.log(data); }, error: function(data){ console.log(data); var obj = JSON.parse(data.responseText); if (obj.title) { $("#title-div").addClass("has-error"); $('#form-errors-title').html(obj.title); } } }) }); }); </script> </div> </body> </html> |
#route Route::get(‘/’,’CustomValDemoController@customVali’); Route::post(‘/ajax’,’CustomValDemoController@ajax’); #conroller
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
<?php /** * Created by IntelliJ IDEA. * User: Akash * Date: 1/25/2017 * Time: 9:37 PM */ namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Input; use Illuminate\Validation\Validator; use App\Http\Requests\TestRequest; class CustomValDemoController extends Controller { public function customVali() { return view('customVali'); } public function customValiPost(Request $request) { /* $this->validate($request, [ 'title' => 'required|min:2|max:5|validateFoo', ]);*/ print_r('done'); } public function ajax(Request $request){ $this->validate($request, [ 'title' => 'required', ]); if($request->ajax()){ return response()->json(['responseText' => 'Success!'], 200); } return 'hola'; } } |
Request Validation and Custom Validation with Image File Input in Laravel 5
01.Create a controller
1 |
php artisan make:controller CustomValDemoController |
02.Route
1 2 |
Route::get('/', 'CustomValDemoController@customVali'); Route::post('customValiPost', 'CustomValDemoController@customValiPost'); |
03.Controller
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Input; use Illuminate\Support\Facades\URL; class CustomValDemoController extends Controller { // public function customVali() { return view('customVali'); } public function customValiPost(Request $request) { $this->validate($request, [ 'title' => 'required', 'picture' => 'required |image ', ]); $avarta = Input::file('picture'); if(strpos($avarta->getClientMimeType(),'image') !== FALSE){ $upload_folder = '/assets/uploads/'; //$file_name = str_random(). '.' . $avarta->getClientOriginalExtension(); $file_name = $avarta->getClientOriginalName(); $avarta->move(public_path() . $upload_folder, $file_name); echo URL::asset($upload_folder . $file_name); // get upload file url } print_r($request->title); } } |
04.and finally the view uploadfile.blade.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
<html lang="en"> <head> <title>Custom Validation Rule Laravel 5</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" > </head> <body> <nav class="navbar navbar-default"> <div class="container-fluid"> <div class="navbar-header"> <a class="navbar-brand" href="#">Custom Validation Rule Laravel 5</a> </div> </div> </nav> <div class="container"> <form action="{{ URL::to('customValiPost') }}" class="form-horizontal" method="post" enctype="multipart/form-data"> <input name="_token" type="hidden" value="{{csrf_token()}}"/> @if (count($errors) > 0) <div class="alert alert-danger"> <ul> @foreach ($errors->all() as $error) <li>{{ $error }}</li> @endforeach </ul> </div> @endif <input type="text" name="title" class="form-control" style="width:30%" placeholder="Add Odd String" /> @if ($errors->has('title')) <span class="help-block"> <strong>{{ $errors->first('title') }}</strong> </span> @endif <br/> <input type="file" class="form-control" name="picture" id="picture"> <button class="btn btn-primary">Save</button> </form> </div> </body> </html> |
05.Create Details…
Component in yii 2
Step1:Make a folder named “components” in your project root folder. step2: write your custom component Details…
Create a Simple to Complex Widget in Yii
First create a folder named “components” in the project root directory. Now create one class Details…
Working with Database in Yii2
Create a database yiibasic #database
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
CREATE TABLE IF NOT EXISTS `employees` ( `Id` int(11) NOT NULL, `first_name` text NOT NULL, `last_name` text NOT NULL, PRIMARY KEY (`Id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Dumping data for table `employees` -- INSERT INTO `employees` (`Id`, `first_name`, `last_name`) VALUES (1, 'aaaa', 'cccc'), (2, 'ssss', 'cccc'); select * from employees; |
create a model