Skip to main content

Posts

Showing posts from August, 2018

concept of class inphp

<div class= "printstr {{ $g -> id }} " style= " border : 0 px solid #a1a1a1 ; background : white ; padding : 10 px ; margin : 0 auto ; text-align : center ; " > <?php $barcode -> setText ( $g -> id ) ; $barcode -> setType (\CodeItNow\BarcodeBundle\Utils\BarcodeGenerator:: Code128 ) ; $barcode -> setScale ( 2 ) ; $barcode -> setThickness ( 25 ) ; $barcode -> setFontSize ( 10 ) ; $code = $barcode -> generate () ; echo '<img src="data:image/png;base64,' . $code . '" />' ; ?> {{--<img alt='testing' src="{{asset('assets/barcode.php?codetype=Code39&size=40&text='.$g->id.'&print=true')}}">--}} <span id= "mprice" name= "mprice" > {{ $g -> selling_price }} </span> </div> <button type= "submit" class= "btn btn-danger btn-block" value= &qu

show only 150 character in front end taking data from backend

REFERENCE :https://stackoverflow.com/questions/11434091/add-if-string-is-too-long-php/11434149 @ if ( strlen ( $item -> description ) <= 150 ) {!! $item -> description !!} @ else {!! substr ( $item -> description , 0 , 150 ) . '...' !!} @ endif @foreach( $mission as $mission ) @if ( strlen( $mission -> description ) <= 150 ) {{ $mission -> description }} @else {{substr( $mission -> description , 0 , 150 ) . '...' }} @endif {{-- The Youth Innovation Lab (YI-Lab) is an initiative of social enterprise with a mission to challenge the TINA (There Is No Alternative) mentality..--}} @endforeach

Laravel validation for API and Laravel

For API : $validator = Validator :: make ( $request -> all (), [ 'name' => 'required|string|max:255' , 'email' => 'required|string|email|max:255|unique:users' , 'phone' => 'required|max:10|unique:users' , 'password' => 'required|string|min:6' ]); // then, if it fails, return the error messages in JSON format if ( $validator -> fails ()) { // return response()->json($validator->messages(), 200); return "Email or Phone Already Exists" ; } else { write code for success } For Laravel Default: in store function: $request -> validate ([ 'name' => 'required|string|max:255' , 'email' => 'required|string|email|max:255|unique:users' , 'phone' => 'required|max:10|unique:users' , 'password' => 'required|string|min:6' ]); in blade: @ if ( $e

form submit without csrf token laravel

step1: go to middleware Csrftoken file <?php namespace App\Http\Middleware ; use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware ; class VerifyCsrfToken extends Middleware { /** * The URIs that should be excluded from CSRF verification. * * @var array */ protected $except = [ 'issue_store' , 'issue_storefront' , 'admin/login' , 'admin/register' , 'admin/logout' , 'login_api' , 'register_api' , 'logout_api' , 'pwreset_api' , 'pwreset' ] ; }

Control registrationn in laravel

https://stackoverflow.com/questions/42695917/laravel-5-4-disable-register-route/42700000 https://laracasts.com/discuss/channels/general-discussion/disable-registration-in-built-in-registration-laravel-53?page=1 These above link are references I did this by changing the constructor in Auth\RegisterController.php From: public function __construct () { $this ->middleware( 'guest' ); } to: public function __construct () { $this ->middleware( 'auth' ); } This way you can create new users if you want, but you have to be logged in first. You could try this. Route :: match ([ 'get' , 'post' ], 'register' , function (){ return redirect ( '/' ); }); Add those routes just below the  Auth::routes()  to override the default registration routes. Any request to the  /register  route will redirect to the baseUrl. This is deceptively easy! You just n

sending value from select2 to controller to store

https://stackoverflow.com/questions/38288899/how-to-store-multi-select-values-in-laravel-5-2 public function setFooAttribute ( $value ) { $this -> attributes [ 'foo' ] = implode ( ',' , $value ); } public function getFooAttribute ( $value ) { return explode ( ',' , $value ); } $news = $request -> input ( 'news' ); $news = implode ( ',' , $news ); $input = $request -> except ( 'news' ); //Assign the "mutated" news value to $input $input [ 'news' ] = $news ; General_news :: create ( $input ); return redirect ()-> back ();