I installed a package in Laravel 5.2 named jonnywilliamson/laragram
And put in config\app.php a alias and service provider like below :
'providers' => [
.
.
.,
Illuminate\Translation\TranslationServiceProvider::class,
Illuminate\Validation\ValidationServiceProvider::class,
Illuminate\View\ViewServiceProvider::class,
Williamson\Laragram\Laravel\LaragramServiceProvider::class,
]
'aliases' => [
.
.
.,
'URL' => Illuminate\Support\Facades\URL::class,
'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facades\View::class,
'TG' => Williamson\Laragram\Laravel\LaragramFacade::class,
]
And in my contoller :
use TG;
public function test()
{
return TG::sendMsg('+989118000000', 'Hello there!');
}
And route:
Route::get('test', 'Services\Auth\Controller\v1_0\AuthController#test');
I also run the following commands :
composer dumpautoload
composer dumpautoload -o
php artisan cache:clear
php artisan clear-compiled
php artisan optimize
But still shows error like:
RuntimeException in Facade.php line 210:
A facade root has not been set.
in Facade.php line 210
at Facade::__callStatic('sendMsg', array('+989118000217', 'Hello there!')) in User.php line 68
at LaragramFacade::sendMsg('+989118000217', 'Hello there!') in User.php line 68
at AuthController->test('fa')
at call_user_func_array(array(object(AuthController), 'test'), array('lang' => 'fa')) in Controller.php line 80
at Controller->callAction('test', array('lang' => 'fa')) in ControllerDispatcher.php line 146
at ControllerDispatcher->call(object(AuthController), object(Route), 'test') in ControllerDispatcher.php line 94
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
How can i fix it?
The function you are trying to call is called sendMessage:
return TG::sendMessage('+989118000000', 'Hello there!');
You are using sendMsg, which is causing the error.
Related
I'm following this tutorial https://www.youtube.com/watch?v=6Oxfb_HNY0U
to build a small lumen testproject.
I'm currently at 27th minute where you are supposed to insert a record through a post request.
To do this, I'm using RESTClient http://restclient.net/
So, the last day I already did my best to tackle this problem, and thanks to SO I also could at least
in part solve the issue:
What does the second paremeter in "json()" do (Lumen/Laravel)?
However, I still get errors instead of new records.
When sending a post request to
http://localhost:8080/api/articles
I get this error:
(1/1) BadMethodCallException
Method Laravel\Lumen\Http\Request::validate does not exist.
in Macroable.php line 103
at Request->__call('validate', array(array('title' => 'required', 'description' => 'required')))in ArticleController.php line 36
at ArticleController->create(object(Request))
at call_user_func_array(array(object(ArticleController), 'create'), array(object(Request)))in BoundMethod.php line 32
at BoundMethod::Illuminate\Container\{closure}()in Util.php line 34
at Util::unwrapIfClosure(object(Closure))in BoundMethod.php line 90
at BoundMethod::callBoundMethod(object(Application), array(object(ArticleController), 'create'), object(Closure))in BoundMethod.php line 34
at BoundMethod::call(object(Application), array(object(ArticleController), 'create'), array(), null)in Container.php line 590
at Container->call(array(object(ArticleController), 'create'), array())in RoutesRequests.php line 376
at Application->callControllerCallable(array(object(ArticleController), 'create'), array())in RoutesRequests.php line 342
at Application->callLumenController(object(ArticleController), 'create', array(true, array('uses' => 'App\\Http\\Controllers\\ArticleController#create'), array()))in RoutesRequests.php line 316
at Application->callControllerAction(array(true, array('uses' => 'App\\Http\\Controllers\\ArticleController#create'), array()))in RoutesRequests.php line 278
at Application->callActionOnArrayBasedRoute(array(true, array('uses' => 'App\\Http\\Controllers\\ArticleController#create'), array()))in RoutesRequests.php line 263
at Application->handleFoundRoute(array(true, array('uses' => 'App\\Http\\Controllers\\ArticleController#create'), array()))in RoutesRequests.php line 165
at Application->Laravel\Lumen\Concerns\{closure}(object(Request))in RoutesRequests.php line 416
at Application->sendThroughPipeline(array(), object(Closure))in RoutesRequests.php line 171
at Application->dispatch(null)in RoutesRequests.php line 108
at Application->run()in index.php line 28
Since I'm new to Lumen/Laravel, I find it hard to guess anything from this error.
I don't know if I just mispelled something, didn't pay attention to scope or anything like that.
Now, here is the code which produced this error:
web.php (routes), Article.php (the model, residing in app folder) and ArticleController.php (Controller):
web.php:
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/
$router->get('/', function () use ($router) {
return $router->app->version();
});
// was simply 'api' in tutorial
$router->group(['prefix' => '/api'], function($router){
$router->get('articles', 'ArticleController#showAllArticles');
$router->get('articles/{id}', 'ArticleController#showOneArticle');
$router->post('articles', 'ArticleController#create');
});
ArticleController.php
<?php
namespace App\Http\Controllers;
use App\Article;
use Illuminate\Http\Request;
class ArticleController extends Controller
{
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
//
}
//
public function showAllArticles(){
return response()->json(Article::get(['title', 'description', 'status'])); // ::get([]) spezifiziert die zu referenzierenden Attribute
// ::all() referenziert alle Attribute einer Tabelle/Relation
}
public function showOneArticle($id){
return response()->json(Article::find($id));
}
public function create(Request $request){
//dd($request); //for debugging whether the request is actually being processed
$validatedData = $request->validate([
'title' => 'required',
'description' => 'required',
]);
//dd($request); //for debugging whether the specified fields are required
//insert record
$article = Article::create($request->all());
return response()->json($article, 201);
}
}
Article.php:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
protected $fillable = [
'title', 'description', 'status'
];
}
Since the function "create()" in this code is modified compared to the tutorial code (see the answer of ege in the SO question referenced at the top), I tried out the tutorial code as well, where the create() function looks like this:
public function create(Request $request){
$this->validation($request, [
'title' => 'required',
'description' => 'required'
]);
$article = Article::create($request->all());
return response()->json($article, 201);
}
and I get another error, in this case:
(1/1) Error
Call to undefined method App\Http\Controllers\ArticleController::validation()
in ArticleController.php line 41
at ArticleController->create(object(Request))
at call_user_func_array(array(object(ArticleController), 'create'), array(object(Request)))in BoundMethod.php line 32
at BoundMethod::Illuminate\Container\{closure}()in Util.php line 34
at Util::unwrapIfClosure(object(Closure))in BoundMethod.php line 90
at BoundMethod::callBoundMethod(object(Application), array(object(ArticleController), 'create'), object(Closure))in BoundMethod.php line 34
at BoundMethod::call(object(Application), array(object(ArticleController), 'create'), array(), null)in Container.php line 590
at Container->call(array(object(ArticleController), 'create'), array())in RoutesRequests.php line 376
at Application->callControllerCallable(array(object(ArticleController), 'create'), array())in RoutesRequests.php line 342
at Application->callLumenController(object(ArticleController), 'create', array(true, array('uses' => 'App\\Http\\Controllers\\ArticleController#create'), array()))in RoutesRequests.php line 316
at Application->callControllerAction(array(true, array('uses' => 'App\\Http\\Controllers\\ArticleController#create'), array()))in RoutesRequests.php line 278
at Application->callActionOnArrayBasedRoute(array(true, array('uses' => 'App\\Http\\Controllers\\ArticleController#create'), array()))in RoutesRequests.php line 263
at Application->handleFoundRoute(array(true, array('uses' => 'App\\Http\\Controllers\\ArticleController#create'), array()))in RoutesRequests.php line 165
at Application->Laravel\Lumen\Concerns\{closure}(object(Request))in RoutesRequests.php line 416
at Application->sendThroughPipeline(array(), object(Closure))in RoutesRequests.php line 171
at Application->dispatch(null)in RoutesRequests.php line 108
at Application->run()in index.php line 28
I'm basically having the same problems with understanding the error as with first error.
I've looked up the lumen documentation here:
https://lumen.laravel.com/docs/6.x/validation
And again I wonder if I didn't understand the scope correctly (what does "this" refer to here, what object is it, what methods can I actually call from it?).
For the sake of completeness, a screenshot of the table I'm referencing with the eloquent model "Article":
https://imgur.com/onXEgzg
Overall I'm just pretty clueless and I would be really thankful if someone could "give me a lift" ^^
Looking at your modified example (2nd version here of your create() method), The first line of the error shows the problem:
Call to undefined method App\Http\Controllers\ArticleController::validation()
So something is wrong with this line in your code:
$this->validation() ...
Checking the link to the Lumen docs that you include:
The $this->validate helper which is available in Lumen ...
So there is a validate() helper - but you're using validation().
I have installed OroCommerce, a Symfony2 based application. I want to have the 'vendor' directory on a higher level outside the users directory. I followed the steps at http://symfony.com/doc/current/configuration/override_dir_structure.html#override-the-vendor-directory but now the namespaces can't be found. I get the following error:
InvalidArgumentException in YamlFileLoader.php line 399: There is no extension able to load the configuration for "framework" (in /home/oro2/public_html/app/config/config_dev.yml). Looked for namespace "framework", found "web_profiler", "sensio_distribution", "debug"
in YamlFileLoader.php line 399
at YamlFileLoader->validate(array('imports' => array(array('resource' => 'config.yml')), 'framework' => array('router' => array('resource' => '%kernel.root_dir%/config/routing_dev.yml'), 'profiler' => array('only_exceptions' => false)), 'web_profiler' => array('toolbar' => true, 'intercept_redirects' => false), 'monolog' => array('handlers' => array('main' => array('type' => 'stream', 'path' => '%kernel.logs_dir%/%kernel.environment%.log', 'level' => 'debug'))), 'oro_assetic' => array('css_debug' => null, 'css_debug_all' => false), 'oro_message_queue' => array('client' => array('traceable_producer' => true))), '/home/oro2/public_html/app/config/config_dev.yml') in YamlFileLoader.php line 369
at YamlFileLoader->loadFile('/home/oro2/public_html/app/config/config_dev.yml') in YamlFileLoader.php line 44
at YamlFileLoader->load('/home/oro2/public_html/app/config/config_dev.yml', null) in DelegatingLoader.php line 45
at DelegatingLoader->load('/home/oro2/public_html/app/config/config_dev.yml') in AppKernel.php line 35
at AppKernel->registerContainerConfiguration(object(DelegatingLoader)) in bootstrap.php.cache line 2776
at Kernel->buildContainer() in bootstrap.php.cache line 2728
at Kernel->initializeContainer() in OroKernel.php line 290
at OroKernel->initializeContainer() in bootstrap.php.cache line 2507
at Kernel->boot() in OroKernel.php line 252
at OroKernel->boot() in bootstrap.php.cache line 2538
at Kernel->handle(object(Request)) in app_dev.php line 33
Am I forgetting something? Does anyone know how to solve this problem?
You are somewhere calling %kernel.root_dir%/config/routing_dev.yml which actually does not exist, because you have moved the config file dir
I am using Lumen to create a website, and while my controllers, routes, and views are well configured, I get an error when I try to use the redirect function in a controller.
This is the error code :
ReflectionException in Container.php line 736: Class url does not exist
in Container.php line 736
at ReflectionClass->__construct('url') in Container.php line 736
at Container->build('url', array()) in Container.php line 631
at Container->make('url', array()) in Application.php line 203
at Application->make('url') in Redirector.php line 39
at Redirector->to('http://opentracker.local/token/archived', '302', array(), null) in helpers.php line 246
at redirect('http://opentracker.local/token/archived') in TokenController.php line 51
at TokenController->unarchive('clickid')
at call_user_func_array(array(object(TokenController), 'unarchive'), array('clickid')) in Container.php line 507
at Container->call(array(object(TokenController), 'unarchive'), array('attribute' => 'clickid')) in RoutesRequests.php line 567
at Application->callControllerCallable(array(object(TokenController), 'unarchive'), array('attribute' => 'clickid')) in RoutesRequests.php line 534
at Application->callLumenController(object(TokenController), 'unarchive', array('1', array('as' => 'token.unarchive', 'uses' => 'App\Http\Controllers\TokenController#unarchive'), array('attribute' => 'clickid'))) in RoutesRequests.php line 507
at Application->callControllerAction(array('1', array('as' => 'token.unarchive', 'uses' => 'App\Http\Controllers\TokenController#unarchive'), array('attribute' => 'clickid'))) in RoutesRequests.php line 475
at Application->callActionOnArrayBasedRoute(array('1', array('as' => 'token.unarchive', 'uses' => 'App\Http\Controllers\TokenController#unarchive'), array('attribute' => 'clickid'))) in RoutesRequests.php line 460
at Application->handleFoundRoute(array('1', array('as' => 'token.unarchive', 'uses' => 'App\Http\Controllers\TokenController#unarchive'), array('attribute' => 'clickid'))) in RoutesRequests.php line 434
at Application->handleDispatcherResponse(array('1', array('as' => 'token.unarchive', 'uses' => 'App\Http\Controllers\TokenController#unarchive'), array('attribute' => 'clickid'))) in RoutesRequests.php line 367
at Application->Laravel\Lumen\Concerns\{closure}() in RoutesRequests.php line 610
at Application->sendThroughPipeline(array(), object(Closure)) in RoutesRequests.php line 368
at Application->dispatch(null) in RoutesRequests.php line 313
at Application->run() in index.php line 28
My route is well recognized, (you can see it transformed as it should in the error).
Here is the code that I use in my controller :
public function unarchive($attribute){
Token::query()->find($attribute)->update(['is_archived'=>0]);
return redirect(route('token.archived'));
}
I also uncommented the following from boostrap/app.php :
$app->withFacades();
$app->withEloquent();
Is there a problem using the function redirect() with Lumen ? I tried both redirect(route()) and redirect()->route(), and they gave the same result.
If you are on 5.2 there is an issue open for this.
Lumen - Github Issues - redirect() doesn't work, Lumen 5.2 #315
You can use the Illuminate\Http\RedirectResponse directly if needed. (from workaround link below):
return new RedirectResponse('login');
return RedirectResponse::create('login');
Possible workaround from Github Issue
Thanks for you interest,
I have create this APP:
// web/index.php
require_once __DIR__.'/../vendor/autoload.php';
use Silex\Application;
use Silex\Provider\TwigServiceProvider;
$app = new Application();
$app['debug'] = true;
$app->register(new TwigServiceProvider(), array(
'twig.path' => __DIR__.'/templates',
'twig.class_path' => __DIR__.'/../vendor/twig/twig/lib',
'twig.options' => array('cache' => __DIR__.'/../cache'),
));
$app->get('/', function () use ($app) {
return $app['twig']->render('base.html.twig', array());
});
return $app;
But, when I load / in instance of base.html.twig be loaded, this error appear:
InvalidArgumentException: Identifier "twig" is not defined.
in /home/victor/workspace/testProject/vendor/pimple/pimple/lib/Pimple.php line 78
at Pimple->offsetGet('twig') in /home/victor/workspace/testProject/src/app.php line 41
at {closure}()
at call_user_func_array(object(Closure), array()) in /home/victor/workspace/testProject/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php line 145
at HttpKernel->handleRaw(object(Request), '1') in /home/victor/workspace/testProject/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php line 66
at HttpKernel->handle(object(Request), '1', true) in /home/victor/workspace/testProject/vendor/silex/silex/src/Silex/Application.php line 538
at Application->handle(object(Request)) in /home/victor/workspace/testProject/vendor/silex/silex/src/Silex/Application.php line 515
at Application->run() in /home/victor/workspace/testProject/web/index.php line 11
I have followed the official tutorial, installed it using composer and double checked all the paths...
Try removing the "twig.class_path" entry.
I have it like this, and it works:
$options = [
'twig.path' => ...,
'twig.options' => [
'strict_variables' => false
]
];
$this->_app->register(new TwigServiceProvider(), $options);
I have installed WAMP server with following details
1. Apache httpd 2.2.22
2. PHP 5.4.3
3. MySQL 5.5.24
I want to run Symfony2 on this so I downloded this
Symfony_Standard_Vendors_2.2.1
And tried to make application from it
I am getting following error for it
1/1 InvalidArgumentException: There is no extension able to load the configuration for "framework" (in D:\Program files\wamp\www\Symfony\app/config/config_dev.yml). Looked for namespace "framework", found "security", "twig", "monolog", "swiftmailer", "assetic", "doctrine", "sensio_framework_extra", "jms_aop", "jms_di_extra", "jms_security_extra", "acme_demo", "web_profiler", "sensio_distribution"
in D:\Program files\wamp\www\Symfony\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Loader\YamlFileLoader.php line 268
at YamlFileLoader->validate(array('imports' => array(array('resource' => 'config.yml')), 'framework' => array('router' => array('resource' => '%kernel.root_dir%/config/routing_dev.yml'), 'profiler' => array('only_exceptions' => false)), 'web_profiler' => array('toolbar'
=> true, 'intercept_redirects' => false), 'monolog' => array('handlers' => array('main' => array('type' => 'stream', 'path'
=> '%kernel.logs_dir%/%kernel.environment%.log', 'level' => 'debug'), 'firephp' => array('type' => 'firephp', 'level' => 'info'), 'chromephp' => array('type' => 'chromephp', 'level' => 'info'))), 'assetic' => array('use_controller' => true)), 'D:\Program files\wamp\www\Symfony\app/config/config_dev.yml') in D:\Program files\wamp\www\Symfony\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Loader\YamlFileLoader.php line 238
at YamlFileLoader->loadFile('D:\Program files\wamp\www\Symfony\app/config/config_dev.yml') in D:\Program files\wamp\www\Symfony\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Loader\YamlFileLoader.php line 42
at YamlFileLoader->load('D:\Program files\wamp\www\Symfony\app/config/config_dev.yml', null) in D:\Program files\wamp\www\Symfony\vendor\symfony\symfony\src\Symfony\Component\Config\Loader\DelegatingLoader.php line 52
at DelegatingLoader->load('D:\Program files\wamp\www\Symfony\app/config/config_dev.yml') in D:\Program files\wamp\www\Symfony\app\AppKernel.php line 36
at AppKernel->registerContainerConfiguration(object(DelegatingLoader)) in D:\Program files\wamp\www\Symfony\app\bootstrap.php.cache line 653
at Kernel->buildContainer() in D:\Program files\wamp\www\Symfony\app\bootstrap.php.cache line 593
at Kernel->initializeContainer() in D:\Program files\wamp\www\Symfony\app\bootstrap.php.cache line 378
at Kernel->boot() in D:\Program files\wamp\www\Symfony\app\bootstrap.php.cache line 409
at Kernel->handle(object(Request)) in D:\Program files\wamp\www\Symfony\web\app_dev.php line 26
Not able to understand, how solve this problem ?
or where is the issue ?
Have you ran check.php, config.php as nicely described in the README.md? I would also recommend to use Symfony with composer, instead of with vendors. Please check the documentation for a proper setup.
This kind of error is usually thrown if you forgot to register a bundle and have already put bundle-specific configurations into app/config/config.yml.
The 'framework' configuration namespace is provided by the FrameworkBundle.
Please make sure you have FrameworkBundle registered in your app/AppKernel.php
<?php
[...]
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
[...]
Please also clear your cache with app/console cache:clear ( probably not working aswell ) or remove the contents of app/cache folder manually.