default route '/' is still listed on top of artisan route:list
I have a project that uses sub-domains.
Now, after following the RouteServiceProvider on how they map the Routes, I finally made a custom RouteServiceProvider for my Subdomains named SubdomainRouteServiceProvider.
Now, I also edited the config/app.php and set the SubdomainRouteServiceProvider ahead of RouteServiceProvider as shown below.
App\Providers\SubdomainRoutesServiceProvider::class,
/*
* Application Service Providers...
*/
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
Now when I typed in the artisan:route-list this shows.
| | GET|HEAD | / | Closure | web |
| company-one.sample.test | GET|HEAD | / | Closure | web |
Is there any thing I need to customize? Or any thing missing?
any help would be great!
Update!! Added Route Files
/*
* Folder: app/Subdomain/CompanyOne/routes/web.php
*/
Route::domain('company-one.sample.test')->group(function() {
Route::get('/', function() {
return view('CompanyOne . views . welcome');
});
});
/*
* Folder: routes/web.php
*/
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
Auth::routes();
Route::get('/', function () {
return view('welcome');
});
1 answer
-
answered 2018-07-11 02:44
Reyn
I think, I was just fooled by looking at the route:list.
when I typed the actual route it shows the page.
See also questions close to this topic
-
Adding item to Array collection api platform
I have a Question entity the relate 'OneToMany' with Answer. The question is how to create a custom endpoint with path='question/{id}/add_answer' to add an answer to a certain question.
-
How to call controller's update function
I am trying to use controller's update function on my dashboard.blade.php page, but when I press on "Save" it switches to show.blade.php page instead of updating.
My dashboard.blade.php page:
@if(count($posts) > 0 ) <table class="table table-striped"> <tr> <th>Title</th> <th>Body</th> <th>Employee Number</th> <th>Edit</th> <th>Save</th> </tr> @foreach($posts as $post) <tr> <td>{{$post->title}}</td> <td><input type='text' name='body'class='form-control' value='{{$post->body}}'></td> <td>{{$post->employee_no}}</td> <td><a href="{{ action("PostsController@update", $post->id) }}" >Save</a></td> <td><a href="/lsapp/public/posts/{{$post->id}}/edit" class="btn btn-default">Edit</a></td> </tr> @endforeach </table> @else <p>You Have No Posts</p> @endif
My update function on PostsController.php page:
public function update(Request $request, $id) { $this->validate($request,[ //'title' => 'required', 'body' => 'required' ]); //Update Post $post = Post::find($id); //$post->title = $request->input('title'); $post->body = $request->input('body'); $post->save(); return redirect('/posts')->with('success','Post Updated'); }
I read that "action" will go to the first route that matches the pattern, but I do not know how to solve this problem.
My web.php page:
Route::get('/', 'PagesController@index'); Route::get('/about', 'PagesController@about'); Route::get('/services', 'PagesController@services'); Route::resource('posts','PostsController'); Auth::routes(); Route::get('/dashboard', 'DashboardController@index');
How can I call the update function correctly from dashboard.blade.php page?
-
How to create sql select by 3 level expression and statement
How to create sql select by 3 level expression and statement
Normally, my website based on SQLite database and the search result will be display by $sql =
"SELECT DISTINCT * FROM amz WHERE Title LIKE \"$qq%\" OR Price LIKE \"$qq%\" GROUP BY Title";.
Above will be search and select query that contains any search keyword from database in column Title or Price.
However, I need to create 3 expression and statement from database as:
- Default will be search and display result as
$sql = "SELECT DISTINCT * FROM amz WHERE Title LIKE \"$qq%\" OR Price LIKE \"$qq%\" GROUP BY Title";
- If can't find any search result from Title and Price column. Then SQL will be check in Category column as
$sql = "SELECT DISTINCT * FROM amz WHERE Category LIKE \"$qq%\" GROUP BY Title";
- Finally, if not match in each column. SQL result will be echo custom message.
I try to create with myself. But it seems the result echo 1.) option only.
Thank you
Regards
- Default will be search and display result as
-
Group collection by month and type user
I have a collection of invoices and to make a chart from it I want to group them in months and in those months a subdivision by the type of the user. I'm not sure how to do this if you can help me out?
db:
- Invoices has column 'date' used to group the invoices in months
- User has column 'type' used to group the invoices in that month by the type
Info:
- with: the relations
- start & end: period
Vue
const invoices = await this.$http.get('/invoices/stats', { params: { with: 'user,customer,extension', start: this.startDate, end: this.endDate, } })
Laravel
public function stats(Request $request) { $result = Invoice::with(explode(',', $request->with)) ->scopes(['period']) ->get(); return $result; }
-
Auth::user & sessions with Socialite
@if( !Auth::check() ) // User has not logged in @else // User has logged in @endif
I am currently using Facebook and that works out so this is not what I'm asking.
I have this snippet on my master.blade.php and it works when I first sign into Facebook however when I go onto another page, such as
/about
it logs me out. I've triedAuth::viaRemember
but this does nothing.How do I store the user's credential in a session so that users won't get logged out just for moving to another page?!
-
Shell (sh): to shift multiple default routes metrics
I need to change metrics of multiple routes by 'sh' script like this:
10 -> 40 20 -> 10 30 -> 20 40 -> 30
Example. Before:
$ ip -4 r | grep default default via 10.1.1.1 dev eth1 proto static metric 10 default via 10.2.2.2 dev eth2 proto static metric 20 default via 10.3.3.3 dev eth3 proto static metric 30 default via 10.4.4.4 dev eth4 proto static metric 40
After:
$ ip -4 r | grep default default via 10.1.1.1 dev eth1 proto static metric 40 default via 10.2.2.2 dev eth2 proto static metric 10 default via 10.3.3.3 dev eth3 proto static metric 20 default via 10.4.4.4 dev eth4 proto static metric 30
How I can do that?
-
Is it possible to use same routes and actions to update data based on objects passed, in rails?
I want to use same
routes
andactions
to update to different data based on theobjects
passed. I want to have to different urls as:# for customer /customers/contact_informations # for shopkeeper /shopkeepers/contact_information
I already have complete controller actions, views and routes for
shopkeepers/contact_information
. I just want same actions to be forcustomers
as well. So here is what I did:- Moved the controller in concern(as module) so that it can be shared in both the controllers (here only one action is showed for understanding and not make the question too long):
module ContactInformations extend ActiveSupport::Concern included do def new redirect_to edit_contact_information_path if @resource.contact_information.present? @contact_information = @resource.build_contact_information @contact_information.build_address @contact_information.emails.build @contact_information.contact_phones.build end end
- In
app/controllers/contact_informations_controller.rb
, included the above model as:
class ContactInformationsController include ContactInformations end
- app/controllers/customers/contact_informations_controller.rb
class ContactInformationsController include ContactInformations end
- Routes declared as:
scope '/customers' do resources :contact_informations end resources :contact_information
The paths I got for this are as below:
Prefix Verb URI Pattern Controller#Action contact_informations GET /customers/contact_informations(.:format) contact_informations#index POST /customers/contact_informations(.:format) contact_informations#create new_contact_information GET /customers/contact_informations/new(.:format) contact_informations#new edit_contact_information GET /customers/contact_informations/:id/edit(.:format) contact_informations#edit contact_information GET /customers/contact_informations/:id(.:format) contact_informations#show PATCH /customers/contact_informations/:id(.:format) contact_informations#update PUT /customers/contact_informations/:id(.:format) contact_informations#update DELETE /customers/contact_informations/:id(.:format) contact_informations#destroy GET /shopkeeper/contact_information/new(.:format) contact_informations#new GET /shopkeeper/contact_information/edit(.:format) contact_informations#edit GET /shopkeeper/contact_information(.:format) contact_informations#show PATCH /shopkeeper/contact_information(.:format) contact_informations#update PUT /shopkeeper/contact_information(.:format) contact_informations#update DELETE /shopkeeper/contact_information(.:format) contact_informations#destroy POST /shopkeeper/contact_information(.:format) contact_informations#create
The
@resource
is used to check whether it iscustomer
orshopkeeper
. However, whenever I try to access thecustomer's
tab, it goes toshopkeeper's
edit form
. I have added the associations as well. Is is possible to use same routes with to different actions? Or am I doing this wrong?Thanks
-
Rails - route redirect based on Route Name
Currently, if I want to redirect to certain page, I must use
to: redirect('/this-is-some-url')
..I wondering if I can redirect to a certain page using
Route Name
such asto: redirect('route_name')
I try below code, but it's not working:
get '/house-url', to: redirect('home') #the value is route name get '/home-url', to: 'home_ctrl#show', as: 'home'
-
Writing custom Laravel queue driver
I'm in the process of writing a custom Laravel 5.5 queue driver for interacting with MQTT. I'm using the Mosquitto MQTT extension.
There's not a lot of documentation on how to implement this. What has me stuck is understanding the expected payload. When my
pop()
method is being called, and myMqttJob
class is being processed, I receive an error about a missing index'job'
. I've tried looking at the implentation of various other drivers including Redis, Beanstalkd, and other custom drivers like for Kafka, and RabbitMQ, but still see where their implementations follow this expected payload structure.If anyone has experience or understanding of how the queues, workers and jobs interact, it'd be much appreciated.
This post is similar to what I'm asking.
-
Draw data in graphics generated by Chart JS
Good afternoon. I'm working with Chart JS and I'm trying to show the existing total per column in a bar graph.
In the backend I use Laravel as a framework and the data I pass from the controller through the
$datacount
variable.This is my query in the controller:
$datacount = DB::table('topics') ->leftJoin('proposals_topics', 'topics.id', '=', 'proposals_topics.topic_id') ->select('topics.name as tpcname', 'proposals_topics.topic_id', \DB::raw('count(topic_id) as total')) ->groupBy('topics.name', 'proposals_topics.topic_id') ->orderBy('topic_id', 'desc') ->get();
The data of the variable I receive in this script:
<script> var datacount = <?= json_encode($datacount, JSON_PRETTY_PRINT); ?>; console.log(datacount); // Bar chart new Chart(document.getElementById("bar-chart"), { type: 'bar', data: { labels: ["Compras y Contrataciones", "Acceso a la Información", "Educación", "Organismos de Control", "Servicio Civil", "Infraestructura", "Energía", "Gestión Financiera", "Salud", "Agua"], datasets: [ { label: "Cantidad generada", backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850","#ffc344","#ff8e17", "#ff4cd8","#ffea4c","#b7ff4c"], data: [datacount.total] } ] }, options: { legend: { display: false }, title: { display: true, text: 'Datos generados por eje temático.' } } }); </script>
I am receiving the results in the console, but I can not show the data of the array.
-
Route not define View: E:\xampp\htdocs\offices\resources\views\admin\offices\create.blade.php ERROR
I am working on a project in which I want to save addresses of offices and the offices create.blade have country and city dependent drop-down for dependent drop-down I did the following code using JavaScript for AJAX call, but when I am running it, I am getting "Route not define error in office.create.blade.
Below is the for offices.create.blade
@section('scripts') <script type="text/javascript"> $("#country").change(function(){ $.ajax({ url: "{{ route('admin.cities.get_by_country') }}?country_id=" + $(this).val(), method: 'GET', success: function(data) { $('#city').html(data.html); } }); }); </script> @endsection
<div class="panel panel-default"> <div class="panel-heading"> @lang('quickadmin.qa_create') </div> <div class="panel-body"> <div class="row"> <div class="col-xs-12 form-group"> {!! Form::label('country_id', trans('quickadmin.offices.fields.country').'*', ['class' => 'control-label']) !!} {!! Form::select('country_id', $countries, old('country_id'), ['class' => 'form-control select2', 'required' => '']) !!} <p class="help-block"></p> @if($errors->has('country_id')) <p class="help-block"> {{ $errors->first('country_id') }} </p> @endif </div> </div> <div class="row"> <div class="col-xs-12 form-group"> {!! Form::label('city_id', trans('quickadmin.offices.fields.city').'*', ['class' => 'control-label']) !!} <select name="city_id" id="city" class="form-control"> <option value="">{{ trans('quickadmin.qa_please_select') }}</option> </select> <p class="help-block"></p> @if($errors->has('city_id')) <p class="help-block"> {{ $errors->first('city_id') }} </p> @endif </div> </div> <div class="row"> <div class="col-xs-12 form-group"> {!! Form::label('address', trans('quickadmin.offices.fields.address').'*', ['class' => 'control-label']) !!} {!! Form::text('address', old('address'), ['class' => 'form-control', 'placeholder' => '', 'required' => '']) !!} <p class="help-block"></p> @if($errors->has('address')) <p class="help-block"> {{ $errors->first('address') }} </p> @endif </div> </div> </div> </div>
CitiesController.php code
public function get_by_country(Request $request) { abort_unless(\Gate::allows('city_access'), 401); if (!$request->country_id) { $html = '<option value="">'.trans('quickadmin.qa_please_select').'</option>'; } else { $html = ''; $cities = City::where('country_id', $request->country_id)->get(); foreach ($cities as $city) { $html .= '<option value="'.$city->id.'">'.$city->name.'</option>'; } } return response()->json(['html' => $html]); }
OfficeController.php code
public function perma_del($id) { if (! Gate::allows('office_delete')) { return abort(401); } $office = Office::onlyTrashed()->findOrFail($id); $office->forceDelete(); return redirect()->route('admin.offices.index'); }
define route in web.php as below
Route::get('cities/get_by_country', 'CitiesController@get_by_country')->name('admin.cities.get_by_country');
I don't know where I did mistake? looking forward for helping me throw this Thanks
-
How to activate laravel
php artisan serve Heading ##enter image description here
-
Laravel maintenance mode --allow ip not working
I am trying to allow my public internet ip through maintenance mode in laravel on a vps.
Does the
--allow
command works over internet or does it work only on the localhost? Because I cannot get pass the maintenance mode page with the following command:$ php artisan down --allow=xx.xx.xx.xx (my public internet ip) Application is now in maintenance mode. $ php artisan up Application is now live.
-
how to print a row from the database using custom artisan command
I am trying to fetch a row from a second database using a custom artisan command in Laravel. Now i want to print the result of the query but I keep getting an error. I would appreciate any help.
I setup the connection to two databases and they are connected and running without problems. the table that I am working with is called person and contains multiple columns such as name, surname, person_id (which is auto increment and primary key) and ssn. I also created a custom artisan command that fetches a row from the database when using
php artisan import-users:DB 12345678
and the query
DB::connection('mysql2')->select('SELECT * FROM person WHERE ssn=?', [$ssn])
the result of the query is placed in the variable $user and now i just want to print it out but i keep getting errors. here is what i tried
$name = $user['name'];
which gives the
ErrorException : Undefined index: name
$this->line($user[0]);
which gives the
ErrorException : Object of class stdClass could not be converted to string
$this->line($user->name);
which give the
ErrorException : Trying to get property 'name' of non-object
I also tried many things but nothing worked. Thanks again
<?php namespace App\Console\Commands; use Illuminate\Console\Command; use DB; class ImportUsers extends Command{ protected $signature = 'import-users:DB {ssn}'; protected $description = 'import users from old database'; public function __construct() { parent::__construct(); } public function handle() { $ssn = $this->argument('ssn'); $user = DB::connection('mysql2')->select('SELECT * FROM person WHERE ssn=?', [$ssn]); $this->line($user->name); $this->info($ssn.' Done'); } }