lundi 1 février 2016

Laravel 5: how to get the paths of all routes?

I need to get a list of the paths of all routes programmatically.

I tried Route::getRoutes() - not working in L5. RouteCollection::getRoutes() - is not a static method.

I bet I can get the RouteCollection from $request, but I don't know how.

K



via Chebli Mohamed

database dynamic field(custom attribute)

Hi I have a table structure as

skills

id   
name

users

 id   
 name

and many to many relation

skill_user

skill_id   
user_id

different users will have different skill which they will select from skills table thats fine. My problem is that there will be few custom skills(custom attributes) that user will fill in a blank text box. How do i manage this kind of problem please help. I am doing this is php/Laravel/Mysql



via Chebli Mohamed

How to add input type="number" in Laravel Blade template?

I want to make input field where user can enter only number. in HTML 5 we use same thing how can i do in blade.

I tried this: {!! Form::number('amount', null, array('class' => 'form-control')) !!}



via Chebli Mohamed

how to make one to many relationship in laravel

i'm trying to make a one to many relationship using eloquent model and want to show the products in the specified category that is my product model :

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\softDeletes;

class Product extends Model
{
    //
    use softDeletes;
    protected $table='products';

    public function category(){
        return $this->belongsTo('App\Category');
    }
}

and that is my category model :

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\softDeletes;

class Category extends Model
{
    //
    use softDeletes;
    protected $table='category';

   public function product(){
    return $this->hasMany('App\Product','category_id','id');
   }
}

and that's the product controller :

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Product;
use App\Category;

class productsController extends Controller
{
    //
    public function getShow($id,Request $request){
            $in=$request->get('id');
            $category=Category::all();
            $product=Product::find($id);
            $products=$product->category()->where('category_id','=',$in);

            return view ('contents.products')->with('products',$products)
                                            ->with('category',$category);
    }
}

and this is the product table :

public function up()
    {
        Schema::create('products', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('category_id');
            $table->string('describtion');
            $table->string('image_name');
            $table->timestamps();
            $table->softDeletes();
        });
    }

and that is the category table :

public function up()
    {
        Schema::create('category', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->timestamps();
            $table->softDeletes();
        });
    }

and it gives me this error : Call to a member function category() on a non-object

so how can i solve it ?



via Chebli Mohamed

Expected response code 220 but got code "", with message "" it work on php 5.4 but 5.6 show error

Expected response code 220 but got code "", with message "" it work on php 5.4 but 5.6 show error

 hereMAIL_DRIVER=smtp
 MAIL_HOST=smtp.gmail.com
 MAIL_PORT=465
 MAIL_USERNAME=amjad.sarwar23@gmail.com
 MAIL_PASSWORD=*******
 MAIL_ENCRYPTION=null
  return [
   'driver' => env('MAIL_DRIVER',' smtp'),
    'host' => env('MAIL_HOST', 'smtp.gmail.com'),
      'port' => env('MAIL_PORT', 465),
     'from' => ['address' =>"amjad.sarwar23@gmail.com" , 'name' => "amjad"],
    'encryption' => 'tls',
  'username' => env('MAIL_USERNAME'),
 'password' => env('MAIL_PASSWORD'),
 'sendmail' => '/usr/sbin/sendmail -bs',
  'pretend' => false,

    Mail::send('email.verify' , ['confirmation_code' => $confirmation_code],            function($message) use ($abc){
        $message->to(Input::get('email'), Input::get('username'))
            ->subject('Verify your email address');
    });



via Chebli Mohamed

Laravel: Route issue

I have the following route which loads the page but the css of the page doesn't loads.

Route::get('admins', function () {
        return view('admins/index');
});

In the contrast the following route loads the same page but here I added index and the page loads correctly. but I also adds index with admins in the browser address bar.

Route::get('admins/index', function () {
        return view('admins/index');
});

I am calling css files in the views like:

<link href="../assets/css/animate.min.css" rel="stylesheet" />

I searched for the solutions but didn't got anything.



via Chebli Mohamed

dimanche 31 janvier 2016

Handle Html tags in input area

Need to allow/disallow some certain html tags in js side. Developing a laravel project where in some input box need to consider certain html elements.

Can be done using string replace function but will take much more time to maintain the list of not allowable items.like the following

function escapeHtml(unsafe) {
    return unsafe
         .replace(/&/g, "&amp;")
         .replace(/</g, "&lt;")
         .replace(/>/g, "&gt;")
         .replace(/"/g, "&quot;")
         .replace(/'/g, "&#039;");
 }

Again the allowed html tag list can also be small so if just want to allow
then the unsafe list will be huge.

I can also do it in server side but cant get any proper source for that.

It will be so helpful if someone can just suggest me what would be the best way for maintaining this allow/disallow html tag list?



via Chebli Mohamed