blocked.com integration with Laravel - php

I am trying to integrate blocked.com in my Laravel 5.2 setup but I don't want to add the blocked.com script in my public folder. I have kept the scripts in app/Libraries folder. Now the issue is to open a PHP file from that folder (from outside public folder).
I am trying this
Route::get('/block-det', [function () {
return redirect()->to('../app/Libraries/blockscript/detector.php');
}]);
But it's redirecting me to https://example.com/app/Libraries/blockscript/index.php

redirect redirects you to a new url, which is why you get redirected to the url you pasted above. You simply want to call that php file. You can do so using require:
Route::get('/block-det', function() {
require '../app/Libraries/blockscript/detector.php';
});
Depending on the location of detector.php you may need to change the path.
Also, it is much more typical, if you are pulling in 3rd party code, to use composer to pull it in, then it is automatically installed in the vendor folder and you can access it from your app that way.

Related

Laravel 404 error while viewing image saved in public directory of laravel project

I created Laravel project and able to make it work to get json output as well. However image link in json is not working.
https://android.factory2homes.com/
json: https://android.factory2homes.com/index.php/api/products
image link:https://android.factory2homes.com/index.php/public/12142.jpg
i tried creating symlink and copied same image in storage folder as well, but not able to make it work.
The public folder in a Laravel project is basically the root folder that shows up on the website URL.
For security issues, you really don't want the users to have the ability to write anything directly on the public folder, because if you are not careful they could overwrite your php scripts and have them do whatever they want.
So generaly speaking you create a simlink inside the public folder to the storage folder that is outside the public directory. Laravel has even a built in artisan command to do that exactly which is:
php artisan storage:link
The URL to any image stored in that folder would be in your example:
https://android.factory2homes.com/storage/12142.jpg
You do not have to put any .php file, or public or anything else.
if the image is inside public then I don't think you need to give the url like index.php/public/someimage.jpg you can just do www.yousiteurl.com/someinage.jpg
I resolved issue by savings images to Public_html folder instead of public folder in Laravel app root folder. Public_html is the path that is visible to public, hence other solutions weren't working.

Codeigniter how to access views/web pages from third party folders

I am in the process of installing SimpleSAML and in the php library, there is a folder called www that has index.php. According to the docs, there is an admin console within it. However, at the moment I am unable to access it via the url www.website.com/third_party/simplesaml/www/index.php.
I am supposed to use the admin console to generate some metadata so I'm just wondering if it is possible to route to a view from there?
I'm thinking that I create a controller and just hard link $this->load->view('url to www') but I'm not sure if that works.
In controller’s constructor add
include APPPATH . 'third_party/simplesaml/www/index.php';
to include the file in your project.
you can set base path in route file and instead of $this->load->view() you can use renderView() function to access view in codeigniter.

404 page not found on every page - Laravel on Hostgator

I'm trying to push a Laravel project to production on Hostgator.
I followed this tutorial. Only the last step, changing one line on paths.php I couldn't accomplish because this file do not exists anymore on Laravel: http://shincoding.com/laravel/installing-configuring-laravel-shared-hosting/
I put all my project files on root/quasenerd_base/quase-nerd, except the content of the public folder, which I moved to root/public_html.
I successfully change the path on index.php to the quasenerd_base folder:
require __DIR__.'/../../quasenerd_base/quase-nerd/bootstrap/autoload.php';
$app = require_once __DIR__.'/../../quasenerd_base/quase-nerd/bootstrap/app.php';
When I access the url http://quasenerd.com.br, I can see my main layout. But it won't load the #section of the page.
In addition, any other url that I try to access returns a 404 page not found. (for example, /login). Apparently I can't access any of my views.
I tryed to add to my index.php:
$app->bind('path.public', function() {
return __DIR__;
});
but it didn't work.
Any ideas?
I have one project on shared hosting and I use this tutorial: YouTube
I hope it will help you.

Angular 2 + angular-cli + Laravel 5.3

Using latest angular-cli, I created new project and everything works fine. Next, I tried to integrate it in Laravel 5.3. I have this project working with systemjs, but I want to switch to webpack and to take advantage of angular-cli.
Problem is that in angular-cli.json I can't specify that index is index.php, it only accepts HTML.
Basically, I can't start the Angular application at all with this setup.
How can I overcome this?
In the end I separated Laravel and Angular 2, as Cristian Sepulveda wrote in the comment. This is the recommended approach anyway.
I make API with Laravel and use it with Angular 2.
In my case I serve the angular app from laravel. I still use webpack to build my assets but have a gulp task which copies the angular index.html to be index.blade.php of which the laravel app serves.
I also use gulp to copy the built files from /dist to /public
I had the same problem and what I found is this related issue in their GitHub issues:
The output folder will always be entirely replaced. You can use the public/ folder to have your index.php which will be copied to your output folder, or output the app to a separate folder and copy the files yourself.
This is by design and will not change. This is a build output folder, not a deploy folder. You should separate those two steps.
So, you can't really achieve what you exactly want, but this is the only workaround I found.
I found only one solution for me.
create build for client side code by ng build --prod
Using gulp copy generated files into Laravel public dir gulp copy (here you can check if old build files exists remove them)
Using gulp-ingect plugin inject copied files into layout gulp inject
-- This can be used in CI and done with automation tools. In result we have inline.js and three *.**.bundle.js files injected. In same main layout i have statically add <base href="/example"> (you can use any defined in Laravel routes root path here) and inside template file which loaded from this path (in my case 'example.blade.php') add angular 2 root element <st-example>Loading...</st-example>
-- By this set up you have root Laravel layout which have inside required by angular 2 root url href and injected scripts files from build. And your template file for current route have root element inside (it included to main layout by simple blade yeild('content')).
P.S. also you must notice that if you are using some http requests in angular 2, after you integrate it into Laravel project this will add csrf protection middleware to each request... And if you have some new errors in requests which work previously just check headers.
Since angular-cli doesn’t allow you to specify index.php, let it be, simply specify index.html then there…
And add an appropriate route into Laravel routing. Like this one, for instance:
Route::any('{path?}', function () {
return File::get(public_path() . '/index.html');
})->where("path", ".+");
Btw, it’s simply a trap for any unknown routes… But I think you get an idea.

how can I use css and js outside of public folder in Laravel 4

i am using laravel 4. Here my css and js are not in public folder. I want to access them through another folder.
I know that by default we can access css and js from public folder only in laravel.
Please help me on this to access from outside of public folder.
This shouldnt be made, it has a reason why the structure is like that. The user can only see scripts in the public folder, that has the advantage that he can not execute scripts.
If the css/js/img files come from a Laravel package try php artisan asset:publish [package]

Categories