laravel-5.2

Cant Download Excel file When calling Laravel Controller from AngularJS

北城以北 提交于 2019-12-06 02:45:12
Hi I am sending some data to laravel controller from angularjs and based on that data i want get data from sql table and download as excel file.But i am unable to download the file Angular code $scope.sendSetField = function (selected_list) { var arr = []; angular.forEach(selected_list, function(value, key){ arr.push(key); }); //console.log(selected_list); $http.post("http://localhost/maxo_ats_v1.00/dashboard/jobsDownload",arr) .then(function(response) { }); Laravel Controller : public function downloadJobsList(Request $request) { // $jobs = CnfFormField::select('id', 'name', 'email', 'created

How To Get Search Query From Multiple Columns in Database

让人想犯罪 __ 提交于 2019-12-06 01:45:49
I have search form to get information from table named books. Right now i'm using this controller public function search(Request $request) { $keyword = $request->input('keyword'); $query = Book::where('judul', 'LIKE', '%' . $keyword . '%'); $book_list = $query->paginate(5); $pagination = $book_list->appends($request->except('page')); $total_book = $book_list->total(); return view('dashboards.index', compact('book_list', 'keyword', 'pagination', 'total_book')); } The problem is the data that i get from the request only available for judul . it just show empty result if the input keyword search

Laravel Validation - How to check if a value exists in a given array?

淺唱寂寞╮ 提交于 2019-12-06 01:27:17
问题 So, okay i tried a lot of rules from validation docs but all give me same error saying Array to string conversion Here is how I add the array: $this->validate($request,[ 'employee' => 'required|in:'.$employee->pluck('id')->toArray(), ],[ 'employee.in' => 'employee does not exists', ]); Any hint on how to achieve this? i created a custom validator but still passing array seems to be not possible 回答1: Implode the array as a string and join it on commas. 'employee' => 'required|in:'.$employee-

How to create symlink from public/storage to storage/app/public in laravel?

╄→尐↘猪︶ㄣ 提交于 2019-12-06 01:02:33
I have no idea on how to create symbolic link or symlink . I am working on File system in laravel 5.2. The document says that i need to create a symbolic link from public/storage to storage/app/public to keep the publicly accessible files in one directory. How to create that symlink or symbolic link? Which file or directory should I place that code? App::make('files')->link(storage_path('app/public'), public_path('storage')); And don't forget to use App after namespace. On Shared Server, where one doesn't have ssh access to run php artisan storage:link this helps me run that from a controller,

FormRequest failed validation returns 500 error instead of 422 with errors (after 5.2 upgrade)

风流意气都作罢 提交于 2019-12-06 00:54:24
问题 After updating from L5.1 to L5.2, I no longer receive a JSON object as response on a failed FormRequest (i.e. on an AJAX post request). Usually I would receive a 422 response like: [ email: 'E-mail is invalid', firstname: 'Firstname must be at least 2 characters' ] But now I receive a 500 error page: I have ensured that my AJAX calls have application/json as Accept header. Update And no, I am not manually catching this exception. I am using the default FormRequest that Laravel provides. As

How to create Eloquent model with relationship?

情到浓时终转凉″ 提交于 2019-12-06 00:52:47
问题 How to create Eloquent model with relationship? I have: Person table id firstname lastname Employee table id person_id position I want to do something like this: Employee::create([ 'firstname' => 'Jack', 'lastname' => 'London', 'position' => 'writer' ]) I know, that can create two model and then associate their. But may be there is a way do this more beautiful? 回答1: First, you have to create relation in your Person model class Person extends Model { protected $fillable = ['firstname',

Check if a class is a Model in Laravel 5

a 夏天 提交于 2019-12-05 23:31:32
I have this code in Laravel 5.2 that checks if a given db table name ($what) has its own Model : public function manage($what) { $model = Str::studly(Str::singular($what)); if (!is_subclass_of($model, 'Model')) { \App::abort(404); } /* [... other stuff ...] */ } The problem is that is_subclass_of always fail, also when the model exist and it's a subclass of Model. I suppose it's a namespace problem, how can I fix it? You may need the full namespace. When I do get_parent_class() on one of my models, it returns Illuminate\Database\Eloquent\Model . So use this instead: $model = 'App\\' . Str:

Laravel 5.2 Login not working

只谈情不闲聊 提交于 2019-12-05 22:34:55
I have created a new Laravel 5.2 installation. And I have run the following command to install the default Laravel authentication; php artisan make:auth The registration form works but the login just redirects home without logging in. And displays no errors when when I enter the wrong credentials. This is my routes file: Route::get('/', 'BaseController@index'); Route::get('/tutors', 'TutorsController@Index'); Route::get('/tutors/myrequest', 'TutorsController@RequestTutor'); Route::get('/tutors/{id}', 'TutorsController@show')->where(['id' => '[0-9]+']); Route::get('/tutors/{GUID}',

Laravel 5.2 Authentication - How can I show logged in user's name and the logout link in every page?

此生再无相见时 提交于 2019-12-05 21:52:10
Laravel 5.2 Authentication I created a new authentication scaffolding in Laravel 5.2 using php artisan make:auth everything worked perfectly except I get Login/Register links even after logging in when I'm in route / but it shows the user's name with a logout link (which is what I want to have in every page) when I'm in route /home How can I show logged in user's name and the logout link in every page? This is because, you are not using the auth middleware on you / route. In your routes.php file the default for this is: Route::get('/', function () { return view('welcome'); }); Try moving this

Get online users in laravel

不想你离开。 提交于 2019-12-05 21:39:45
I have one user for login to demo of my script. I want get how many people online now. I use laravel 5.2 What am I do? You could keep sessions in a DB and use last_activity column to determine how many users are currently online. https://laravel.com/docs/5.1/session#introduction There is a laravel plugin to achieve this. here's the link : https://github.com/thomastkim/laravel-online-users you can use the below package in order to get online users or determine if a user is online or not. https://github.com/shetabit/visitor 来源: https://stackoverflow.com/questions/38811097/get-online-users-in