I have a new project I created recently using the latest Laravel 9 and Jetstream with Livewire. I've created some migrations and seeders and they run perfectly with Artisan.
Now I'm ready to start creating my homepage. I create a brand-new file called index.blade.php in the resources/views directory. I give it the contents of "Hello World." That's it. No boilerplate, no HTML, nothing. I update the main / route to point to index instead of welcome. I then create a Feature Test to make sure that getting the / route returns a status code of 200. It runs great. The page also loads fine in a browser displaying the "Hello World" text.
Now comes the part where I get confused. I change the "Hello World" text to just say "Hello". Refreshing the browser, I get the following message:
If I run the same Feature Test again, it still passes fine. Then, when I refresh the browser again after having run the test, it loads!
I have tried out many different procedures, but it seems like the page simply will not load whenever I make any change to it at all. However, any time I run the Feature Test, then reload the page in the browser, it'll show up fine. For reference, here's the test:
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
class AppTest extends TestCase
{
/**
* Testing that the app's main page loads successfully.
*
* #return void
*/
public function test_app_home_page_loads_successfully(): void
{
$response = $this->get('/');
$response->assertStatus(200);
}
}
What on earth is causing this odd behavior?
As #IGP and #matiaslauriti pointed out in the comments, there is clearly a permissions issue with storage/framework/views. However, it is not with the directory itself, just a single file (out of dozens) in that directory.
I do not know how or why, but that one file (83b9b...) had an owner:group of "root:root". The rest of the files in that directory are owned by me and my group.
What makes this odd is that this stays true even when I run the Feature Test, so I do not know why running that Feature Test causes the view to load fine even while that file is still owned by "root:root".
Manually changing that file's owner:group does, indeed, fix the issue. My only concern now is not knowing how it got changed in the first place and, thus, not knowing how to prevent this from happening again in the future. If anyone has any ideas, I'm open. For now, however, I'll go ahead and close this.
Thank you, #IGP and #matiaslauriti.
Related
I have a "reportSchedule" model which contains the report name and a cron_request column such as */15 * * * *.
I want to be able to adjust the cron within the database and affect the times which the report is requested. For example, the following is working from directly within the console/Kernel.php:
ReportSchedule::all()->each(function(ReportSchedule $reportSchedule) use($schedule){
if(isset($reportSchedule->cron_request)){
$schedule->call(function() use ($reportSchedule) {
ReportRequestNow::dispatch($reportSchedule);
})->cron($reportSchedule->cron_request);
}
});
However, having the model called from directly within the kernel causes other issues. For example database migrations now do not work and errors are thrown when caching the routes or running route:list. In general, it does not seem to like it!
So my idea was either create a seeder job or put this into its own schedule, however neither work.
// Doesnt work - the every minute schuedle is called but ReportRequestNow is never reached.
$schedule->call(function() use($schedule){
ReportSchedule::all()->each(function(ReportSchedule $reportSchedule) use($schedule){
if(isset($reportSchedule->cron_request)){
$schedule->call(function() use ($reportSchedule) {
ReportRequestNow::dispatch($reportSchedule);
})->cron($reportSchedule->cron_request);
}
});
})->everyMinute();
// Also does not work
$schedule->job(new ReportScheduleSeeder(), 'high')->everyMinute();
Can anyone suggest a why this does not work or how to get it working?
However, having the model called from directly within the kernel
causes other issues. For example database migrations now do not work
and errors are thrown when caching the routes or running route:list.
In general, it does not seem to like it!
Seems that there's some syntax errors (maybe some classes aren't listed in use?)
Have you checked laravel and PHP logs? Most likely there will be some explanations.
I have written a core controller in application/core--MY_Controller.php:
class MY_ProtectedController extends CI_Controller{
public function __construct(){
echo("I luv bd1"); //This echo's
parent::__construct();
echo("I luv bd2"); //this one even couldn't reached to
$this->CI=& get_instance();
$this->CI->load->library('permission');
$this->CI->load->library('authentication');
$this->CI->load->model('commonmodel');
$this->CI->load->model('admin/usermodel');
$this->CI->load->library('imagelib');
$this->CI->load->library('facebook');
}
As you could see the first echo is echoed but the second cant get reached because parent::__construct calls CI_Controllers's __construct which fails somewhere in method resolution order(successive calls to other methods in it---I guess). If I keep debugging I think it's gonna take me the whole day excepting I have already wasted two days behind this.
FYI: I'm on EC2 VPS. installed php5.4*,apache2.4*,mysql5.5* CI:2.1.3, php.ini:display_errors=On,
CI: error_reporting(E_ALL)
[But CI's error log is not being written may be for the same reason. I have given log folder 755 perm.]
More Debug: Calling controllers without inheriting from MY_protected also results in the same.
In the matter of course: autoload,library load, view load,helper load ALL ARE FAILING.
Please Help!
Try installing a fresh copy of codeigniter, i.e. Download Codeigniter and Paste only the files you have changed or added.
For instance you most likely added new files to the controllers folder, so move your work in to the, fresh install of codeigniter's, controllers folder. do this for all you work..
I know this is not a proper solution, but at least if you do it this way you can continue working. I can not see with the info you provided, why it would not run anything after parent::__construct(); or even run that line.
Hope this helps.
I am brand new to Laravel 4 and seeing if I can convert my website over to it (previously written without a framework). I can't get AJAX (via jQuery) to interact properly with my controller.
So firstly, the controller I am working in is called IndexController.php and has a function called types which is shown below:
class IndexController extends BaseController {
// Other controller functions
public function types($brand) {
$types = DB::select('select * from aircraft_types where brand_id = ?', array($brand));
echo json_encode($types);
}
}
The function returns the data from the database (in JSON format). I have then created a route to this controller and function as follows:
Route::get('types/{id}', array('uses'=>'IndexController#types'));
I have doubled checked that the route and function are working by going to //localhost/lavarel/public/types/1 and indeed it returns the correct JSON data.
The jquery function in question is below:
function updateTypes($brand) {
$("#type").append('<option value="test">Test...</option>'); // This executes correctly
$.getJSON('/types/'+$brand, function(data) {
$("#type").append('<option value="test 2">Test 2...</option>'); // This does not
// Some other JSON related code
});
To test where the function works, I have inserted two lines which edit the item I am using. The function is being called correctly as the first 'Test' option is being appended. However, it never seems to activate the callback function as the second line of test code is not executed.
I suspect the issue is the URL I am providing to JavaScript '/types/'+$brand. I have seen in some tutorials a BASE var used before the URL I provide, but I don't see why my code above wouldn't work. Any pointers?
Can anyone explain to me where I am going wrong?
Your base path to your laravel project is localhost/laravel/public/ but your AJAX-request goes to just localhost. There're some methods for fixing this.
Method 1:
This is the most preffered method. (in my opinion)
Instead of using nginx, apache for starting a web server, you can use PHP's built in web server.
Open a terminal window (or cmd in Windows), cd into the main directory for your project (the one with vendor, app and public directories) and type the command php artisan serve. This will create a PHP-server on localhost:8000 and your base path will be /.
There's a lot of options, for example php artisan help serve" if you want to see them all.
After you've done so your code should work.
Method 2
If you want to use nginx or apache you should add a virtualhost for your project.
That can be done though the configs.
Apache: http://httpd.apache.org/docs/current/vhosts/examples.html
Nginx: http://wiki.nginx.org/ServerBlockExample
After that you should add a new entry to the hosts file.
Method 3
As you said you could add a BASE variable before the '/types/'+$brand.
Your request goes to localhost/types/$brand.
It should go to localhost/laravel/public/types/$brand.
Just replace '/types/'$brand with '/laravel/public/types'+$brand
Use HTML 'base' meta tag
<!doctype html>
<html lang="en">
<head>
...
<base href="{{ URL::to('/') }}"/>
...
Declaring this tag, you ensure that every relative URL will be based on project's real, absolute URL (http://localhost/my-laravel-project/public/), not on Localhost's URL (http://localhost)
I was following documentaion till the end, tested one html template with smarty and then cut it. Then I found out that controllers do not work as expected – whatever name I create in myapp/conrollers, 'hello.php' for example, that contains class described in docs, i. e.
class Hello_Controller extends TinyMVC_Controller
{
function index()
{
echo "Hello World.";
}
function time()
{
echo "The time is now.";
}
}
I can’t show it. So the name of the file is a prefix for the controller class name, all seems to be ok here, but going to /index.php/hello returns what is in 'default.php'. I’ve even tried to change default controller to 'hello' in myapp/configs/application.php by setting $config['default_controller'], but the framework behaves like if it’s always work with the 'default.php'. There is no errors on screen or in logs (I checked twice every option in configs of my web server and interpreter), I totally don’t know what to do with that goddamn piece of crap, I can’t even write on its forum because waiting for ‘administration approval’ for several days.
I had to dig inside of the framework to find an answer. And it is when it checks for a controller file it uses file_exists() which do not respect include path. Googling ‘TinyMVC+file_exists’ gave me link to that topic, where is written that they had fixed it in SVN version.
I am learning how to use codeIgniter as my php framework. I am reading through the documentation and watching the intro video and just generally following along with the first tutorial, but it's not working for me.
I have created a controller called "test.php" and a view called "test_view". The controller for this class is exactly like "welcome.php" and the view file just has some static html. However, when I go to index.php/test I get a 404 error.
I have also tried manipulating the original welcome files so that instead of calling a view it just echos "testing", yet I still see the original welcome message! I've tried clearing my browsing cash and refreshing, but to no avail.
Any suggestions? Thanks.
Edit: Here's the code for controllers/test.php
<?php
class Test extends Controller {
//Just trying to get it to echo test
public function index()
{
echo "test";
//$this->load->view('test_view');
}
}
?>
Try looking at this page in the documentation - this might solve your problem.
This basically means you should try typing index.php?/test/ instead (notice the question-mark).
First of all, check the above link. Might be useful.
If not, then...
Try changing the default controller in the config file ('routes.php') to something else (probably, to 'test'), then try loading index.php. Just to test whether the whole system works (or not).
Check whether mod_rewrite is loaded (in your server .conf-file, if you're using Apache).
Try using the latest build of the framework. AFAIK, the name of the controller class for now is "CI_Controller".
Finally, try removing the word 'public' before the declaration of the function. AFAIR, CI enable you to make private functions in controllers just by using prefix (which is set in the config file) at the beginning of the name of the function (thus making all the other functions public).
But most certainly the problem is with the mod_rewrite. If not, try debugging with die('Page found'); instead of echo - this will allow you to track possible redirects on the page.