laravel-5.2

Laravel 5 single route multiple controller method

跟風遠走 提交于 2020-03-19 05:09:27
问题 I have a route with parameter Route::get('forum/{ques}', "ForumQuestionsController@show"); Now I want a route something like Route::get('forum/add', ['middleware' => 'auth:student', 'uses' => "ForumQuestionsController@add"]); well when I hit localhost:800/forum/add I get routed to ForumQuestionsController@show instead of ForumQuestionsController@add Well I know I can handle this in show method of ForumQuestionsController and return a different view based on the paramter. But I want it in this

Return first element from relation with `Lazy Eager Loading` [Laravel 5.2]

假装没事ソ 提交于 2020-03-06 03:08:08
问题 I have relation like this: public function message() { return $this->hasMany('Engine\Message'); } inside my Conversation model. and for each conversation I need to get last message. Here is what I tried, but this will get only one message for first conversation but will not get message from other conversations... $con = Conversation::all(); $con->load(['message' => function ($q) use ( &$mess ) { $mess = $q->first(); }]); return $con; I don't wana query for each record... Anyone know how to

Laravel route redirect without closure for route cache

喜夏-厌秋 提交于 2020-02-28 06:14:24
问题 I have this code on my routes.php file that do a redirect. Though the problem is that whenever I ran php artisan route:cache command, it gives me an error of Unable to prepare route [article/{params}] for serialization. Uses Closure. I know this has something to do with routes not allowing it to be cached if it have a closure. But how could I make a workaround for this redirect? Route::get('article/{params}', function($params) { return Redirect::to($params, 301); }); 回答1: Route caching does

How to validate phone number in laravel 5.2? [closed]

Deadly 提交于 2020-02-16 18:46:12
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 days ago . I want to validate user input phone number where number should be exactly 11 and started with 01 and value field should be number only. How do I do it using Laravel validation? Here is my controller: public function saveUser(Request $request){ $this->validate($request,[ 'name' => 'required|max:120', 'email' =>

how to use IN operator in laravel query (eleqouent and raw query)?

浪尽此生 提交于 2020-02-07 17:16:34
问题 I need to use the IN operator to get the data from the database. I tried using it as below and got an error: $pr =DB::('select * from prstuff p where p.pid in (select pid from prdrop)'); I am new to Laravel and don't know exactly how to use the operators like IN , so please explain to me how to use it. 回答1: you can set the custom select in DB::raw() like this : DB::select(DB::raw('select * from prstuff p where p.pid in (select pid from prdrop)')); or you can use whereIn() like this: DB::table

how to use IN operator in laravel query (eleqouent and raw query)?

☆樱花仙子☆ 提交于 2020-02-07 17:16:14
问题 I need to use the IN operator to get the data from the database. I tried using it as below and got an error: $pr =DB::('select * from prstuff p where p.pid in (select pid from prdrop)'); I am new to Laravel and don't know exactly how to use the operators like IN , so please explain to me how to use it. 回答1: you can set the custom select in DB::raw() like this : DB::select(DB::raw('select * from prstuff p where p.pid in (select pid from prdrop)')); or you can use whereIn() like this: DB::table

Laravel how to check validate unique table two field

帅比萌擦擦* 提交于 2020-02-02 12:59:47
问题 I have tableA that there are 2 field 1. song_id 2. playlist_id I want to check laravel validate unique func example: I have inserted data id => 1 song_id => 2 playlist_id => 34 then I have to insert data again I want to check that if playlist_id => 34 already inserted song_id = 2 show message "already insert" but if playlist_id => 34 insert song_id = 3 allow insert thank you for your help! 回答1: This is the rule that need to apply. Tested with sample data and it works as desired. use

Laravel 5.2: asset path not working on server

末鹿安然 提交于 2020-01-25 18:28:06
问题 My laravel 5.2 app unable to fetch the stylesheet from the public/css directory on the production server but can fetch stylesheets on the local machine! here is how I am linking my files: <link href="{{asset('css/clock.css')}}" rel="stylesheet" media="all" /> I also tried bunch of different ways: <link href="{{URL::asset('css/clock.css')}}" rel="stylesheet" media="all" /> OR: {{HTML::style('css/clock.css')}} but nothing worked on server! but it is not able to fetch the css! when I check the

ErrorException: Trying to get property of non-object: (using laravel)

最后都变了- 提交于 2020-01-25 16:31:10
问题 ErrorException: Trying to get property of non-object: PHP beginner Trying to retreive data from database. show.blade.php @extends('main') @section('title','| Station details') @section('content') <h1>{{ $station->station_name }}</h1> <p class="lead">{{ $station->station_name }}</p> @endsection controller - <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests; use App\Station; use Session; class StationController extends Controller { /** * Display a listing

ErrorException: Trying to get property of non-object: (using laravel)

牧云@^-^@ 提交于 2020-01-25 16:30:32
问题 ErrorException: Trying to get property of non-object: PHP beginner Trying to retreive data from database. show.blade.php @extends('main') @section('title','| Station details') @section('content') <h1>{{ $station->station_name }}</h1> <p class="lead">{{ $station->station_name }}</p> @endsection controller - <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests; use App\Station; use Session; class StationController extends Controller { /** * Display a listing