The #isset directive is not been rendered by Laravel 5.4 - laravel-5.4

I'm developing a blade view on Laravel 5.4 which tests if a variable is set. If it is not set, the blade must present a little piece of html code placed into it. The problem is Laravel ignores or doesn't recognize the #isset directive rendering the string as if it was a simple html code. See the picture:
I have done a ugly workaround using #if(! empty($test) ). And I already tried to clean the cache with php artisan cache:clear.
Did someone know something that can cause this problem? Thanks a lot!

I solved my problem updating Laravel Framework from 5.4.15 to 5.4.36.
First, stop your server (if you are using php artisan serve).
Then run composer update on root directory of the project.
Probably you need to run php artisan cache:clear before serve the project again, in my case it wasn't necessary.
It's a strange behavior of Laravel witch probably is a little bug on Laravel Framework 5.4.15 or earlier.

Related

URL paths that work in Vue 2 and Laravel 8?

I'm working on a vue/laravel project and can't use one url path for both the dev environment (npm run hot) and production environment (php artisan serve).
This CSS example works only for php artisan:
background: url("../images/image.png")
while this only works for npm run hot:
background: url("/public/images/image.png")
Is there a method that works in both?
As far as I know you should refer to from src. So moving the image.png to /src/images/image.png it would be something like background: url("#/images/image.png"), as # refers to src.
EDIT: Approach with laravel and vue-cli
If you need to set up different path´s for your enviroments, vue-cli could be your choice. This gives you the possibility to create a vue.config.js and set up a publicPath for your enviroments.
Further Information: Integrate Laravel with a Vue CLI app
I've ended up just using php artisan serve with hot reload instead of using npm run hot. Now I have only one dev environment. You can see here how to set it up.

"false" showing up mysteriously in terminal?

Terminal is giving me an issue where it prints "false"
Additionally, "false" shows up before the html view in the Laravel output.
I am running into this on codecourse's Classified's Site tutorial
Any idea how to remedy?
More detail:
I think what set this off was I changed the config/database.php for mysql from strict = true to false (have since changed back).
After changing mysql strict = true, I reloaded vagrant with provision on and did a migrate:reset and migrate then reseeded the database. Yet, when I run commands in terminal (eg. php artisan migrate), 'false' gets displayed on the next line before the migrations happen. and annoyingly, my website displays "false" in the top of the view, before the html doctype in the source gets written I took a look around the routes and views and cannot see how the false is creeping in there (especially since I changed it back to true!)
Any idea how to remedy, or suggestions for what to try?
See sample terminal Code below
vagrant#homestead:~/code/fresh$ php artisan migrate
falseMigrating: 2018_02_16_130447_create_listings_table
Migrated: 2018_02_16_130447_create_listings_table
vagrant#homestead:~/code/fresh$ php artisan make:controller Listing\ListingController
falseController created successfully.
vagrant#homestead:~/code/fresh$
Thank you Sam for the answer, I had accidentally put "false" ABOVE the start of the php declaration on the first line of my database config file
A PHP file can contain non-php and remain valid, i.e the following is valid:
false <?php echo '<h1>Hello World!</h1>'; ?>
That would produce the following:
false <h1>Hello World!</h1>
Laravel configuration files are simple PHP files that return an array, that file is included by the framework and the app configuration is populated from the values in the array. The behaviour you're seeing is indicative of a file within your application containing content that shouldn't be there, and based on what you were doing when the issue occured it's probably one of your configuration files.
Run the following command from your project root:
$ grep -r "false" config
Then review each instance of "false". You'll most likely find that at the top of your config/database.php file you've mistakenly placed false before the opening tag <?php.
For future reference, if you're using version control it is much easier to identify the cause of issues like this because you can step through every change you've made since the issue started. GitHub has a great desktop client that makes version control very easy :-)

How can I use ReactJS as a static website?

I want to develop my static web application with React. I have just done with the Tic-tac-toe getting started tutorial. Are there anyways I can "compile" (or whatever the term is) ReactJS straight into my HTML file? So, far to run that ReactJS application I need to run it with a server from Yarn.
I prefer to not use CDN because I want to update and manage the dependencies.
Let say, for my starting point, I want to have that Tic-tac-toe game from official React getting started tutorial to be served with just one HTML file (CSS and JS in that one HTML file). I want to see if this is possible or not, so I don't care about the best practice for this question.
You should have a look at Gatsby JS
It's a static site generator for React. Probably that's what you're looking for.
Run npm run build or yarn build and see the output in the build folder. It generates static HTML, CSS and Javascript.
Sounds like you are using Yarn with create-react-app. If so you are running:
yarn start
Now run:
yarn build
See more info here: https://github.com/facebookincubator/create-react-app
The static web application will be built to a build folder. You will find all of the static assets there like JS, CSS and HTML.
I have tested. yarn build works only with a server. Even python3 -m http.server works. So, no! ReactJS downloaded from non-Bower package manager will not work without server out-of-the-box.

Running Ruby script with HTML button?

I have a Ruby script that I run through the Command Line locally. Now I want to run that script through a browser, with a simple HTML button. Is there any way to make a simple HTML page and run the script similar to a JS onclick event? OR will I have to set up a rails environment first?
To run a Ruby script, you need a Ruby interpreter. JavaScript can be run locally by the browser that executes the HTML page, Ruby no.
Therefore, your cannot run the Ruby code directly in the browser. There are several possible solutions.
You can host the Ruby script somewhere, and have the HTML page reference it. If the script is reasonably simple, you can use one of those services that run a Ruby script in a sandbox.
But if it's a Rails app, no way. You need to host it somewhere.
Short answer, you need a server/computer with the Ruby interpreter to execute your script. It can't be executed by the client browser.
There are a few options here. Depending on your use case the most likely two are:
Convert your Ruby script into JavaScript via Opal so that it can run in the browser.
Set up a simple server with Sinatra and run it on a server somewhere, then call it via AJAX.
There are couple of options available for your use case but I would use Sinatra for this. Here is a very simple example for you.
your_file.rb
require 'sinatra'
get '/' do
"<a href='/another-file'> Link to another file </a>"
end
get '/another-file' do
"Today is #{Time.now}"
end
If you do not have sinatra gem installed then please try
gem install sinatra
Once done then you can run your script on your desire port (I'm using 5000)
ruby your_file.rb -p 5000
Now you can browse your simple app at http://localhost:5000. Please checkout sinatra website for complete documentation.

How to call a ruby script from webpage and output the results?

Okay so maybe you guys can advise me. Here is what I am attempting to do.
I am trying to call my ruby script from a html form on a website that has already been created.
The form needs to pass a variable entered in a text box to the ruby script.
Once the script is finished (it's doing a sql query) it needs to output the results to the webpage.
What do you guys think this is the best way to go about doing this? I looked at Rails but the webpage is already created and I don't want to create full scale webapp. I also looked at Rack, but I am not sure if that is the best option. Thanks!
Ruby code is executed in a RVM (MRI, JRUBY, etc). It is served by a Webserver(NGINX, Apache, etc) which processes it by a RVM WebServer stack(CGI/Phussion Passenger) and passes it through Ruby middleware (Rack) and associated frameworks (Sinatra, Rails, etc).
Some WebServers have RVM Stacks built into them Puma, Unicorn, etc.
Using nginx to proxy-pass a specific request path from a url to a RVM enabled webstack + sinatra app would work fine. You might include the uri/pages as an iframe to inject into your current server as well.
A simple example of exposing a sinatra app running in a rvm unicorn stack through nginx.
https://github.com/p8952/nginx-unicorn-sinatra